async-control

Ultimate asynchronous control flow goodness with built-in hook system and compose, series, define and parallel methods. Uses async.map and async.mapSeries methods. Allows passing custom iterator function.
Install
npm i async-control --save
Usage
For more use-cases see the tests
const fs = const asyncControl = asyncControl
AsyncControl
Initialize
AsyncControl
withoptions
to control enabling/disablingoptions.settle
, passing customiterator
and pass different hooks - before, after, etc.
Params
options
{Object=}
.series
Iterate over
value
in series flow. Theasync.mapSeries
method is used.
Params
value
{Object|Array|Function}: The value to iterate over.options
{Object=}: Can pass different hooks - before, after, beforeEach, afterEach.done
{Function=}: If not passed, thunk is returned (function that accepts callback).returns
{Function}: Orundefined
ifdone
is passed.
Example
var fs = var asyncControl = asyncControl //=> ENOENT Error, ['foo', undefined]
.parallel
Iterate over
value
in parallel flow. Theasync.map
method is used.
Params
value
{Object|Array|Function}: The value to iterate over.options
{Object=}: Can pass different hooks - before, after, beforeEach, afterEach.done
{Function=}: If not passed, thunk is returned (function that accepts callback).returns
{Function}: Orundefined
ifdone
is passed.
Example
var fs = var asyncControl = asyncControl
.compose
Compose
series
orparallel
method. Can be used to createsettleSeries
orsettleParallel
methods for example.
Params
flow
{String}: Type of flow, one of'series'
or'parallel'
.options
{Object=}: Can pass different hooks - before, after, beforeEach, afterEach.returns
{Function}: Composedseries
orparallel
method, depends onflow
.
Example
var fs = var asyncControl = // the internal `.series` method is created this way - using `.compose`var series = asyncControl //=> null, [123, ENOENT Error, 456]
Custom iterator
Below example shows how to create your own iterator using
asyncControl.define
method. This also can be done by passing function tooptions.iterator
. It recievesapp
andoptions
and must return function which is directly passed toasync.map
and/orasync.mapSeries
methods.
Params
app
{Object}: instance of AsyncControlopts
{Object}: theapp
optionsreturns
{Function}: iterator passed directly to async.map / async.mapSeries
Example
const util = const asyncControl = asyncControlasyncControl
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.