Skip to content

Instantly share code, notes, and snippets.

@nlacasse
Created December 6, 2010 20:59
Show Gist options
  • Save nlacasse/730937 to your computer and use it in GitHub Desktop.
Save nlacasse/730937 to your computer and use it in GitHub Desktop.
asyncFor(each)
exports.asyncFor = function (start, end, eachCallback, endCallback) {
var helper = function (i) {
if (i >= end) {
return process.nextTick(function () {endCallback();});
}
eachCallback(i);
process.nextTick(function () {helper (i+1);});
};
return helper(start);
};
exports.asyncForEach = function (array, eachCallback, endCallback) {
return exports.asyncFor(0, array.length,
function (i) { eachCallback(array[i]); },
function (i) { endCallback(); }
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment