lateral
v3.0.5
Published
Like forEachAsync and Join had a baby: sequences out n batches of async functions rather than all at once. Part of FuturesJS (Browser, Node.js, Bower, Pakmanager)
Downloads
584
Readme
Lateral
Basically a thread pool for asynchronous calls. The number of calls is limited to n.
Installation
Node.JS (Server):
npm install lateral
Browser:
pakmanager build lateral
#or ender build lateral
Standalone Usage
var Lateral = require('lateral')
, maxCallsAtOnce = 4 // default
, lateral
;
lateral = Lateral.create(function (complete, item, i) {
setTimeout(function () {
console.log(item);
complete();
}, 500);
}, maxCallsAtOnce);
lateral.add(['a', 'b', 'c', 'd']).when(function () {
console.log('did all the things');
});
lateral.add(['d', 'e', 'f', 'g']).when(function () {
console.log('did all the things');
});
API
Creates a Sequence-ish object for the purpose of synchronizing other Futures.
Core
lateral = Lateral.create(handler, n)
- create a Lateral that will execute
fn
on each item to do at mostn
things at once
- create a Lateral that will execute
lateral.add(arr)
- addsarr
to be handled byfn
lateral.add(arr).when(callback)
- Fires
callback
when all items in thearr
batch have been handled
- Fires