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 when = function(){ | |
if( !(this instanceof when) ) return new when(arguments); //return new instance of itself | |
var self = this; //cached so the syntax of code within the function is more readable | |
self.pending = Array.prototype.slice.call(arguments[0]); //convert arguments passed in to array | |
self.pending_length = self.pending.length; //cache length of the arguments array | |
self.results = []; //container for results of async functions | |
(function(){ // define pass() within this context so that the outer scope of self(this) is available when pass() is executed within the user's async 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 after = function _after(count, f) { | |
var c = 0, results = []; | |
return function _callback() { | |
results.push( arguments.length > 1 ? arguments : arguments[0] ); | |
if (++c === count) { | |
f.apply(this, results); | |
} | |
}; | |
}; |