Last active
August 29, 2015 13:58
-
-
Save nescalante/10043230 to your computer and use it in GitHub Desktop.
Array batch execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function batch(array, size, callback, done) { | |
var index = 0, | |
processed = 0; | |
while (index < size) { | |
next(); | |
} | |
function next() { | |
var item = array[index]; | |
if (item) { | |
callback(item, index, function () { | |
processed++; | |
if (array[index]) { | |
next(); | |
} | |
else if (processed === array.length && done) { | |
done(); | |
} | |
}); | |
} | |
index++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kill the server with simultaneous calls
Usage