Loop through asynchronous code with events
Installation
npm install evented-async-loop
Usage
Check examples
and test
folders for more details.
Basic
'use strict'; var asyncLoop = ;var dummyArray = ; //Make an array of asynchronous functionsvar arr = ; var loop = asyncLoop; loop; loop; loopstart;
Chaining
//All methods accept .next are chainableloopstart;
Exit early
loopstart;
Data propagation
// loop.start(...).on() is ok too!loopstart0 'blah'; // Pass any number of arguments
Error handling
loopstart;
API
Events
next[element, i, array, arg1, ...]
done[arg1, ...]
error[arg1, ...]
Methods
.start([arg1, ...])
: Start the loop.Passes arguments to the firstnext
event.next([arg1, ...])
: Go to the next iteration. Passes agruments tonext
event. If the loop is completeddone
is emitted instead..done([arg1, ...])
: Stop the loop early. Passes arguments todone
event.error([err])
: Emit anerror
event.break()
: Break the loop. it wont emitdone
Test
Change your working directory to the project's root, npm install
to get the development dependencies and then npm test