Created
February 9, 2011 22:00
-
-
Save michiel/819397 to your computer and use it in GitHub Desktop.
Run 10000 async calls through a sequencer
This file contains hidden or 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
// | |
// 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