PromiseList object used for handling a list of Promises
Example
var myFunc = function(){
var promise = new Promise();
//callback the promise after 10 Secs
setTimeout(hitch(promise, "callback"), 10000);
return promise.promise();
}
var myFunc2 = function(){
var promises =[];
for(var i = 0; i < 10; i++){
promises.push(myFunc);
}
//create a new promise list with all 10 promises
return new PromiseList(promises).promise();
}
myFunc.then(function(success){}, function(error){})
//chain promise operations
myFunc.chain(myfunc).then(function(success){}, function(error){})
myFunc2.then(function(success){}, function(error){})
//chain promise operations
myFunc2.chain(myfunc).then(function(success){}, function(error){})
Extends
function (defs,normalizeResults){
this.__errors = [];
this.__results = [];
this.normalizeResults = base.isBoolean(normalizeResults) ? normalizeResults : false;
this._super(arguments);
if (defs && defs.length) {
this.__defLength = defs.length;
forEach(defs, this.__addPromise, this);
} else {
this.__resolve();
}
}
Add a promise to our chain
Argumentsthe promise to add to our chain
the index of the promise in our chain
function (promise,i){
promise.addCallback(hitch(this, function () {
var args = argsToArray(arguments);
args.unshift(i);
this.callback.apply(this, args);
}));
promise.addErrback(hitch(this, function () {
var args = argsToArray(arguments);
args.unshift(i);
this.errback.apply(this, args);
}));
}
Resolves the promise
Source
function (){
if (!this.__fired) {
this.__fired = true;
var cbs = this.__errors.length ? this.__errorCbs : this.__cbs,
len = cbs.length, i,
results = this.__errors.length ? this.__errors : this.__results;
for (i = 0; i < len; i++) {
this.__callNextTick(cbs[i], results);
}
}
}
MIT https://github.com/C2FO/comb/raw/master/LICENSE
git clone git://github.com/C2FO/comb.git