Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run 10000 async calls through a sequencer
//
// Example #1 : sequence 10000 async calls
//
function sequence(arr) {
var self = function() {
arr.length && arr.shift()(self);
}
self();
}
//
// Build an array with 10000 sequencable async calls
//
var asyncCalls = [];
for (var i=0;i<10000;i++) {
(function(no) {
asyncCalls.push(
function(callback) {
console.log("Call #" + no);
setTimeout(callback, 1);
}
);
})(i);
}
sequence(asyncCalls);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment