Skip to content

Instantly share code, notes, and snippets.

@qubyte
Last active December 12, 2015 03:18
Show Gist options
  • Save qubyte/4705801 to your computer and use it in GitHub Desktop.
Save qubyte/4705801 to your computer and use it in GitHub Desktop.
An asynchronous for each series runner. Feed this a contiguous array of functions that accept a single (callback([error])) argument.
// Simple asynchronous forEach.
function forEachSeries(list, func, callback) {
var listIndex = 0;
function doOne(err) {
if (err) {
return callback(err);
}
var thisElem = list[listIndex];
if (!thisElem) {
return callback();
}
listIndex += 1;
func(thisElem, doOne);
}
doOne();
}
@qubyte
Copy link
Author

qubyte commented Apr 15, 2014

Updated to avoid array slicing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment