Last active
August 29, 2015 13:56
-
-
Save oxUnd/9200485 to your computer and use it in GitHub Desktop.
RE: http://krasimirtsonev.com/blog/article/7-lines-JavaScript-library-for-calling-asynchronous-functions
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 queue = function(funcs, scope) { | |
(function next() { | |
if(funcs.length > 0) { | |
funcs.shift().apply(scope || {}, [next].concat(Array.prototype.slice.call(arguments, 0))); | |
} | |
})(); | |
}; | |
var obj = { | |
value: null | |
}; | |
queue([ | |
function(callback) { | |
var self = this; | |
setTimeout(function() { | |
self.value = 10; | |
callback(20); | |
}, 200); | |
}, | |
function(callback, add) { | |
console.log(this.value + add); | |
callback(); | |
}, | |
function() { | |
console.log(obj.value); | |
} | |
], obj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment