1 if(!dojo._hasResource["dojo.DeferredList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.DeferredList"] = true;
3 dojo.provide("dojo.DeferredList");
4 dojo.declare("dojo.DeferredList", dojo.Deferred, {
5 constructor: function(/*Array*/ list, /*Boolean?*/ fireOnOneCallback, /*Boolean?*/ fireOnOneErrback, /*Boolean?*/ consumeErrors, /*Function?*/ canceller){
7 // Provides event handling for a group of Deferred objects.
9 // DeferredList takes an array of existing deferreds and returns a new deferred of its own
10 // this new deferred will typically have its callback fired when all of the deferreds in
11 // the given list have fired their own deferreds. The parameters `fireOnOneCallback` and
12 // fireOnOneErrback, will fire before all the deferreds as appropriate
15 // The list of deferreds to be synchronizied with this DeferredList
17 // Will cause the DeferredLists callback to be fired as soon as any
18 // of the deferreds in its list have been fired instead of waiting until
19 // the entire list has finished
21 // Will cause the errback to fire upon any of the deferreds errback
23 // A deferred canceller function, see dojo.Deferred
25 this.resultList = new Array(this.list.length);
29 this.id = this._nextId();
32 this.results = [null, null];
33 this.canceller = canceller;
34 this.silentlyCancelled = false;
36 if(this.list.length === 0 && !fireOnOneCallback){
37 this.callback(this.resultList);
40 this.finishedCount = 0;
41 this.fireOnOneCallback = fireOnOneCallback;
42 this.fireOnOneErrback = fireOnOneErrback;
43 this.consumeErrors = consumeErrors;
45 dojo.forEach(this.list, function(d, index){
46 d.addCallback(this, function(r){ this._cbDeferred(index, true, r); return r; });
47 d.addErrback(this, function(r){ this._cbDeferred(index, false, r); return r; });
51 _cbDeferred: function(index, succeeded, result){
53 // The DeferredLists' callback handler
55 this.resultList[index] = [succeeded, result]; this.finishedCount += 1;
57 if(succeeded && this.fireOnOneCallback){
58 this.callback([index, result]);
59 }else if(!succeeded && this.fireOnOneErrback){
61 }else if(this.finishedCount == this.list.length){
62 this.callback(this.resultList);
65 if(!succeeded && this.consumeErrors){
71 gatherResults: function(deferredList){
73 // Gathers the results of the deferreds for packaging
74 // as the parameters to the Deferred Lists' callback
76 var d = new dojo.DeferredList(deferredList, false, true, false);
77 d.addCallback(function(results){
79 dojo.forEach(results, function(result){