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)
forEachAsync that allows
n async calls at once.
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!
npm install lateral
You can install from bower:
bower install lateral
Or download the raw file from https://raw.github.com/FuturesJS/lateral/master/lateral.js:
Or build with pakmanager:
pakmanager build lateral
;'use strict';var Lateral = windowLateral || require'lateral'LateralmaxCallsAtOnce = 4 // defaultlateral;setTimeoutconsole.logitem;complete;500;lateral = LateralcreateonEach maxCallsAtOnce;lateraladd'a' 'b' 'c' 'd'thenconsole.log'first batch done';;lateraladd'd' 'e' 'f' 'g'thenconsole.log'second batch done';;lateralthenconsole.log'did all the things';;;
lateral = Lateral.create(fn, n)
fnon each item to do at most
nthings at once
arrto be handled by
cbis called when all in
callbackwhen all items in added arrays have been handled
The code is a little hairy and could use some cleaning.