Skip to content

Instantly share code, notes, and snippets.

@FLYBYME
Created August 16, 2012 22:32
Show Gist options
  • Save FLYBYME/3374210 to your computer and use it in GitHub Desktop.
Save FLYBYME/3374210 to your computer and use it in GitHub Desktop.
Array.prototype.forLoop = function(worker, callBack) {
var self = this;
var returnData = [];
var loop = function(i) {
if(i === self.length) {
return callBack(returnData);
}
process.nextTick(function() {
worker.call(self, self[i], function(d) {
returnData.push(d);
loop(++i);
});
});
};
loop(0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment