Last active
August 29, 2015 14:05
-
-
Save A1rPun/088dc65c3e17c5a64f17 to your computer and use it in GitHub Desktop.
This file contains 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 async = { | |
waterfall: function (listOfRequests, callback) { | |
var callbacks = 0; | |
function handleCallback() { | |
callbacks++; | |
if (callbacks === listOfRequests.length) { | |
callback(); | |
} else { | |
listOfRequests[callbacks](handleCallback); | |
} | |
} | |
if (listOfRequests[0]) { | |
listOfRequests[0](handleCallback); | |
} | |
}, | |
parallel: function(listOfRequests, callback){ | |
var callbacks = 0; | |
function handleCallback(){ | |
callbacks++; | |
if (callbacks === listOfRequests.length) callback(); | |
} | |
for (var i = 0; i < listOfRequests.length; i++){ | |
listOfRequests[i](handleCallback); | |
} | |
} | |
} |
This file contains 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
async.waterfall([function (cb) { | |
setTimeout(function () { | |
console.log('1'); | |
cb(); | |
}, 10); | |
}, function (cb) { | |
console.log('2'); | |
cb(); | |
}, function (cb) { | |
setTimeout(function () { | |
console.log('3'); | |
cb(); | |
}, 100); | |
}], function () { console.log('done') }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment