Lateral
Basically a forEachAsync
that allows n
async calls at once.
Another way to think of it is as a thread pool for JavaScript.
Say you have 500 http requests that you want to get done
10 at a time in batches of 400, 50, and 50 and you want
to know when each batch (and all batches) have finished... lateral
is your guy!
Node.js Installation
Node.JS (Server):
npm install lateral
Browser Installation
You can install from bower:
bower install lateral
Or download the raw file from https://raw.github.com/FuturesJS/lateral/master/lateral.js:
wget https://raw.github.com/FuturesJS/lateral/master/lateral.js
Or build with pakmanager:
pakmanager build lateral
Usage
; { 'use strict'; var Lateral = windowLateral || Lateral maxCallsAtOnce = 4 // default lateral ; { ; } lateral = Lateral; lateral; lateral; lateral;};
API
lateral = Lateral.create(fn, 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).then(cb)
- addsarr
to be handled byfn
andcb
is called when all inarr
are handledlateral.then(callback)
- Fires
callback
when all items in added arrays have been handled
- Fires
TODO
The code is a little hairy and could use some cleaning.