Skip to content

Instantly share code, notes, and snippets.

@michiel
Created February 9, 2011 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michiel/819397 to your computer and use it in GitHub Desktop.
Save michiel/819397 to your computer and use it in GitHub Desktop.
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