callback-sequence
Make a new callback to run callbacks in sequence or parallel.
Callbacks can be made async like gulp tasks.
Example
var thunkify = var Readable = Readablevar gulp = gulp gulp gulp gulp {} { process} { return Promise} { var s = s return s}
API
var Runner = var runner = input: false output: false exports = moduleexports = runnerthunkifyexportsrun = exportssequence = runnersequenceexportsparallel = runnerparallelexportsseries = runnerseriesexportsRunner = Runner
Runner
var runner = Runner(opts)
Create a new runner instance.
opts
input
Specify whether to pass the results of the previous callback to the next as arguments.
Type: Boolean
Default: true
var Runner = Runner var runner = runner1 2
output
Specify whether to deliver results.
Type: Boolean
Default: true
If false
, the final results will always be []
.
run
Specify a runner function to run each callback.
Type: Function
, Object
Default: null
If Function
, it receives a callback followed by a list of arguments,
and should return a promise to fetch the results (Array
).
If Object
, it is passed to
Runner of run-callback
to create a runner function.
cb = Runner.prototype.thunkify(...tasks)
Return a callback to run the specified tasks in the appearance order.
var runner = runner1
Runner.prototype.sequence(tasks)
Run tasks
in sequence.
NOTE: directly nested array of tasks will be run with Runner.prototype.parallel
.
var runner = runner // 1// 2// 3// 4// DONE
Callbacks can be added dynamically:
var runner = var count = 5var tasks = var res = { process}runner tasks
Runner.prototype.parallel(tasks)
Run the specified tasks in parallel.
NOTE: directly nested array of tasks will be run with Runner.prototype.sequence
.
var runner = var res = runner
Runner.prototype.series(...tasks)
Run tasks
in sequence.
However, while the results of sequence
is that of the last task,
the results of series
is an array containing all results of the tasks.
In addition, the results of the previous task will not be passed to the next as arguments.
NOTE: each element will be passed to Runner.prototype.sequence
.
var runner = runner