asynccond
async series with conditional exit
Async series functions with the ability to conditionally pre-exit the sequence.
seq
furthermore allows to trap errors within the sequence.
The functions provided are backwards compatible with async.
Table of Contents
Description
eachSeries(arr, iterator, callback)
Applies the function iterator
to each item in arr
in series.
The iterator
is called with an item from arr
, and a callback
when it has finished. If the iterator
passes an error to its
callback, the main callback
is immediately called with the error.
If a condition is applied on the internal callback of iterator
,
it pre-exits the series.
Example
;
Parameters
arr: Array
, array of items which are passed to iterator
iterator: function
, function(item, cb)
cb
needs to be called inside iterator
callback: function
, is of type function(err, result)
and called after running the series
series(tasks, callback)
Run the functions in the tasks
array in series, each one running
once the previous function has completed. If any functions in the
series pass an error to its callback, no more functions are run,
and callback
is immediately called with the value of the error.
Otherwise, callback
receives an array of results when tasks
have completed.
It is also possible to pass an object instead of an array for
tasks
. Each property will be run as a function, and the results
will be passed to the final callback as an object instead of an
array. This can be a more readable way of handling results from
series.
The series can be exited immediately on any internal callback.
Example
var series = series;var data = 7;
Parameters
tasks: Array | Object
, the async functions to run in series
callback: function
, is of type function(err, result)
and called after running the series
seq(tasks)
Creates a function which is a composition of the passed asynchronous functions. Each function consumes the return value of the function that follows.
Each function is executed with the this binding of the composed function.
Example
var seq = seq;var start = 1; start { // the final callback function //> err = null //> result = 14 };
Parameters
tasks: Array | Object | function
, Array or Object or Arguments list of functions function(data, callback)
where callback
is of type function(err, result, [exit])
Returns: function
, call with (data, callback)
where callback
is of type function(err, result)
Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work or correctly attributed with the source of its origin and licence.
License
Copyright (c) 2015 commenthol (MIT License)
See LICENSE for more info.