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

Constructor

Defined promise.js Source
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();
   }
           
}
            

__addPromise Function Private


Defined promise.js

Add a promise to our chain

Arguments Source
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);
   }));
           
}
    

__resolve Function Private


Defined promise.js

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);
       }
   }
           
}
    

License

MIT https://github.com/C2FO/comb/raw/master/LICENSE

Meta