Skip to content

Instantly share code, notes, and snippets.

@7fe
7fe / whenthen.js
Created July 31, 2011 04:13 — forked from geuis/whenthen.js
When-Then (pseudo javascript Promise)
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
@7fe
7fe / Async_After.js
Created July 30, 2011 15:44 — forked from Raynos/Async_After.js
Flow control utility for node.js
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);
}
};
};