co-utils
Runs an array of yieldables in series using co
.series(arr, [ctx], [args], [timeout]) Calls an array of yielables in series
arr
Array of yieldables
ctx
This context (Optional)
args
Arguments passed to each yieldable (Optional)
timeout
Optional number of a timeout in milliseconds. Defaults to 30000
let co = ; // co can be used as usual; let promises = Promise; Promise; Promise;; // calls an array of yieldables in seriesco; // if one of the promises rejects or an error will be thrown,// then the main promise will fail let promises = Promise; Promise; Promise;; co;
.pipe(arr, [ctx], pipeObj, [timeout])
Pipes an object through an array of yieldables in series
arr
Array of yieldables
ctx
This context (Optional)
pipeObj
Object to be piped through yieldables arr
timeout
Optional number of a timeout in milliseconds. Defaults to 30000
let arr = { obja = true; return obj } { objb = true; return obj } { objc = true; return obj }; obj = {};co
yieldables
We call yieldable a function, a generator or a promise, supported by co-series.
Promises
var promise = { ;};
Generators
var { return 'banana';}
Callback functions
var { ;}
Callbacks with promises
var { promise;}
Promise returning functions
var { return Promise;}
Call it all together
co;
Arguments and this context
Passing arguments or a this context to yieldable is very easy. co.series accepts a this context as second parameter and an arguments array as third parameter. Both of them are optional.
let ctx = prefix: '#'; let args = 'apple' 'banana'; let { return thisprefix + arg1;} let { return thisprefix + arg2;}co;
Timeout
co.series timeouts after 30 seconds by default. The timeout can be changed by passing a number of milliseconds as fourth or last parameter
let ctx = prefix: '#'; let args = 'apple' 'banana'; let { // never call done()} let { return thisprefix + arg2;}co;