Last active
December 12, 2015 03:18
-
-
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.
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
// 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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to avoid array slicing.