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
sequence = (arr) -> | |
self = -> | |
if arr.length then arr.shift() self | |
self() | |
async = (callback) -> | |
console.log "Calling callback after 1s" | |
setTimeout callback, 1000 | |
sequence [async, async, async] |
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 #3 : sequence 10000 async calls in a pipeline, with max 500 open | |
// | |
function pipeline(arr, maxOpenCalls, finalCallback) { | |
var openCalls = 0; | |
function callback() { | |
if (--openCalls < maxOpenCalls) { |
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 #2 : sequence 10000 async calls in blocks of 500 using a collector | |
// | |
function sequence(arr) { | |
var self = function() { | |
arr.length && arr.shift()(self); | |
} | |
self(); | |
} |
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(); |
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
Sequencer = function(lambdas) { | |
var self = this; | |
this.start = function() { | |
this.next(); | |
} | |
this.next = function() { | |
if (lambdas.length != 0) { |
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
var BLOCKSIZE = 500; | |
var dataset = []; // Assuming, of course, that there's something in here.. | |
var renderActions = []; | |
for (var i=0; i<dataset.length; i+= BLOCKSIZE) { | |
renderActions.push((function(offset) { | |
return function(callback) { | |
// |
NewerOlder