PromiseList object used for handling a list of Promises
ExampleExtends
- 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){})
- 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){
- 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;
- });
- }
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 < len; i++) {
- spreadArgs(cbs[i], [results]);
- }
- });
- }
- }
MIT https://github.com/C2FO/comb/raw/master/LICENSE
git clone git://github.com/C2FO/comb.git