async-base-iterator
Basic iterator for async library that handles async and synchronous functions, also emits
beforeEach
,afterEach
anderror
events. Using async-simple-iterator and used in async-control.
Install
npm i async-base-iterator --save
Usage
For more use-cases see the tests
var base = // or get constructorvar AsyncBaseIterator = AsyncBaseIterator
API
AsyncBaseIterator
Initialize
AsyncBaseIterator
withoptions
, see also async-simple-iterator.
Params
options
{Object=}: PassbeforeEach
,afterEach
anderror
hooks orsettle
option.
Example
var ctrl = var AsyncBaseIterator = AsyncBaseIterator var fs = var base = settle: true { console } { console }var iterator = base ctrl
.makeIterator
Make iterator to be passed to async lib.
Params
[options]
{Object=}: PassbeforeEach
,afterEach
anderror
hooks orsettle
option.returns
{Function}: Iterator that can be passed to any async method.
Events
emits
:beforeEach
with signaturefn, next
emits
:afterEach
with signatureerr, res, fn, next
emits
:error
with signatureerr, res, fn, next
Example
var ctrl = var base = base var iterator = base { throw 'two err'} ctrl
.doneCallback
Helper, wrapper function. Use it to wrap you final callback function which you pass to async lib. This may be needed if you want to catch if error happens in the final callback function, because actually it is executed in promise as the other functions in stack. There's just no other way to handle errors from final callback, it is rare case, but sometimes it may be needed. Be aware of that.
Params
<fn>
{Function}: called with arguments passed to the returned callback[done]
{Function=}: optionalreturns
{Function}: callback function that you can pass to async methods
Example
var base = var ctrl = var assert = ctrl
Related
- async: Higher-order functions and common patterns for asynchronous code | homepage
- 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. | homepage
- async-simple-iterator: Making simple iterator for async lib that adds beforeEach, afterEach, error hooks and support for settling. It also emits
beforeEach
,afterEach
anderror
events. | homepage - iterator-async: Iterate over a stack of async functions. | homepage
- iterator-promise: Iterate over a stack of functions. | homepage
- letta: Let's move to promises! Drop-in replacement for
co@4
(passing 100% tests), but on steroids. Accepts sync, async and generator functions. | homepage - relike: Simple promisify a callback-style function with sane defaults. Support promisify-ing sync functions. | homepage
- then-callback: Wrap a promise to allow passing callback to
.then
of given promise, also works as normal.then
| homepage
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.