multitask
How it works
Create tasks
.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 ;
Run tasks and handle responses
.run
returns a Bluebird promise, which exposes a then
method (for handling results) and a catch
method (for catching errors).
multitask ;
Reset before re-running
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 ;
Example implementation
var tasks = ; tasks; tasks; mtask; { mtask ;} ;;
Output
- 'stage 1' task begins (1000ms pause)
- 'stage 2' task begins (2000ms pause)
- 'report' task begins
- runner exits with arguments
{ '0': [ 2, 1 ], '1': [Function] }
- runner logs 'done' with arguments
{ '0': [ 3, undefined, 'also undefined', 1, 2 ] }