diff options
Diffstat (limited to 'lib/dojo/DeferredList.js')
-rw-r--r-- | lib/dojo/DeferredList.js | 119 |
1 files changed, 72 insertions, 47 deletions
diff --git a/lib/dojo/DeferredList.js b/lib/dojo/DeferredList.js index 6a1a1aae6..a8156aba2 100644 --- a/lib/dojo/DeferredList.js +++ b/lib/dojo/DeferredList.js @@ -5,54 +5,79 @@ */ -if(!dojo._hasResource["dojo.DeferredList"]){ -dojo._hasResource["dojo.DeferredList"]=true; +if(!dojo._hasResource["dojo.DeferredList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojo.DeferredList"] = true; dojo.provide("dojo.DeferredList"); -dojo.DeferredList=function(_1,_2,_3,_4,_5){ -var _6=[]; -dojo.Deferred.call(this); -var _7=this; -if(_1.length===0&&!_2){ -this.resolve([0,[]]); -} -var _8=0; -dojo.forEach(_1,function(_9,i){ -_9.then(function(_a){ -if(_2){ -_7.resolve([i,_a]); -}else{ -_b(true,_a); -} -},function(_c){ -if(_3){ -_7.reject(_c); -}else{ -_b(false,_c); -} -if(_4){ -return null; -} -throw _c; -}); -function _b(_d,_e){ -_6[i]=[_d,_e]; -_8++; -if(_8===_1.length){ -_7.resolve(_6); -} +dojo.DeferredList = function(/*Array*/ list, /*Boolean?*/ fireOnOneCallback, /*Boolean?*/ fireOnOneErrback, /*Boolean?*/ consumeErrors, /*Function?*/ canceller){ + // summary: + // Provides event handling for a group of Deferred objects. + // description: + // DeferredList takes an array of existing deferreds and returns a new deferred of its own + // this new deferred will typically have its callback fired when all of the deferreds in + // the given list have fired their own deferreds. The parameters `fireOnOneCallback` and + // fireOnOneErrback, will fire before all the deferreds as appropriate + // + // list: + // The list of deferreds to be synchronizied with this DeferredList + // fireOnOneCallback: + // Will cause the DeferredLists callback to be fired as soon as any + // of the deferreds in its list have been fired instead of waiting until + // the entire list has finished + // fireonOneErrback: + // Will cause the errback to fire upon any of the deferreds errback + // canceller: + // A deferred canceller function, see dojo.Deferred + var resultList = []; + dojo.Deferred.call(this); + var self = this; + if(list.length === 0 && !fireOnOneCallback){ + this.resolve([0, []]); + } + var finished = 0; + dojo.forEach(list, function(item, i){ + item.then(function(result){ + if(fireOnOneCallback){ + self.resolve([i, result]); + }else{ + addResult(true, result); + } + },function(error){ + if(fireOnOneErrback){ + self.reject(error); + }else{ + addResult(false, error); + } + if(consumeErrors){ + return null; + } + throw error; + }); + function addResult(succeeded, result){ + resultList[i] = [succeeded, result]; + finished++; + if(finished === list.length){ + self.resolve(resultList); + } + + } + }); }; -}); -}; -dojo.DeferredList.prototype=new dojo.Deferred(); -dojo.DeferredList.prototype.gatherResults=function(_f){ -var d=new dojo.DeferredList(_f,false,true,false); -d.addCallback(function(_10){ -var ret=[]; -dojo.forEach(_10,function(_11){ -ret.push(_11[1]); -}); -return ret; -}); -return d; +dojo.DeferredList.prototype = new dojo.Deferred(); + +dojo.DeferredList.prototype.gatherResults= function(deferredList){ + // summary: + // Gathers the results of the deferreds for packaging + // as the parameters to the Deferred Lists' callback + + var d = new dojo.DeferredList(deferredList, false, true, false); + d.addCallback(function(results){ + var ret = []; + dojo.forEach(results, function(result){ + ret.push(result[1]); + }); + return ret; + }); + return d; }; + } |