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){
   var self = this;
   promise.then(
       function () {
           var args = argsToArray(arguments);
           args.unshift(i);
           spreadArgs(self.callback, args, self);
           promise = i = self = null;
       },
       function () {
           var args = argsToArray(arguments);
           args.unshift(i);
           spreadArgs(self.errback, args, self);
           promise = i = self = null;
       });
           
}
    

__resolve Function Private


Defined promise.js

Resolves the promise

Source
function (){
   if (!this.__fired) {
       this.__fired = true;
       var self = this;
       nextTick(function () {
           var cbs = self.__errors.length ? self.__errorCbs : self.__cbs,
               len = cbs.length, i,
               results = self.__errors.length ? self.__errors : self.__results;
           for (i = 0; i &lt; len; i++) {
               spreadArgs(cbs[i], [results]);
           }
       });
   }
           
}
    

License

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

Meta