
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
.set
defines a task and its optional dependencies. Tasks and task dependencies are wrapped with Bluebird promises. Each task will be called with a last argument (explained below) containing a "done" function that completes the task and optionally returns a value.
multitask
.set('first task', function(done){
// do some asynchronous work and call done()
done({ response: "tada!" });
})
.set('next task', ['list', 'of', 'dependent', 'tasks'], function(res, done){
// notice this task depends on others ^
// insert an argument to get an array of values returned by them ^ ...
done({ task_count: res.length });
})
.set('task three', ['first task', 'next task'], function(done){
// ... or omit that extra argument if the results of dependent tasks are not needed
// the -last- argument will always be a `done` function
});
.run
returns a Bluebird promise, which exposes a then
method (for handling results) and a catch
method (for catching errors).
multitask
.run(['list', 'of', 'tasks'])
.then(function(res){
/* res == array containing results of all tasks */
})
.catch(function(err){
/* err == any errors thrown by tasks */
});
If you're running tasks with a cron or interval, .reset
will clear out previous results before re-running. This can be useful when hitting an API for time-sensitive data.
multitask
.reset()
.run(['first', 'next']);
var tasks = require('./');
tasks.set('stage 1', function(done){
setTimeout(function(){
done(1);
}, 1000);
});
tasks.set('stage 2', ['stage 1'], function(result, done){
// receive prior result by providing argument ^
setTimeout(function(){
done(result * 2);
}, 2000);
});
mtask.set('report', ['stage 2', 'stage 1'], function(result, done){
done( result[0] + result[1] );
});
function init(){
mtask
.reset()
.run(['report', undefined, 'also undefined', 'stage 1', 'stage 2'])
.then(function(result){
console.log('done', result);
})
.catch(function(err){
console.log('err', err);
});
}
init();
setInterval(init, 5000);
Output
{ '0': [ 2, 1 ], '1': [Function] }
{ '0': [ 3, undefined, 'also undefined', 1, 2 ] }
FAQs
Asynchronous task-runner
We found that multitask demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.