2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo._hasResource["dojo.DeferredList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo._hasResource["dojo.DeferredList"] = true;
10 dojo.provide("dojo.DeferredList");
11 dojo.DeferredList = function(/*Array*/ list, /*Boolean?*/ fireOnOneCallback, /*Boolean?*/ fireOnOneErrback, /*Boolean?*/ consumeErrors, /*Function?*/ canceller){
13 // Provides event handling for a group of Deferred objects.
15 // DeferredList takes an array of existing deferreds and returns a new deferred of its own
16 // this new deferred will typically have its callback fired when all of the deferreds in
17 // the given list have fired their own deferreds. The parameters `fireOnOneCallback` and
18 // fireOnOneErrback, will fire before all the deferreds as appropriate
21 // The list of deferreds to be synchronizied with this DeferredList
23 // Will cause the DeferredLists callback to be fired as soon as any
24 // of the deferreds in its list have been fired instead of waiting until
25 // the entire list has finished
27 // Will cause the errback to fire upon any of the deferreds errback
29 // A deferred canceller function, see dojo.Deferred
31 dojo.Deferred.call(this);
33 if(list.length === 0 && !fireOnOneCallback){
34 this.resolve([0, []]);
37 dojo.forEach(list, function(item, i){
38 item.then(function(result){
39 if(fireOnOneCallback){
40 self.resolve([i, result]);
42 addResult(true, result);
48 addResult(false, error);
55 function addResult(succeeded, result){
56 resultList[i] = [succeeded, result];
58 if(finished === list.length){
59 self.resolve(resultList);
65 dojo.DeferredList.prototype = new dojo.Deferred();
67 dojo.DeferredList.prototype.gatherResults= function(deferredList){
69 // Gathers the results of the deferreds for packaging
70 // as the parameters to the Deferred Lists' callback
72 var d = new dojo.DeferredList(deferredList, false, true, false);
73 d.addCallback(function(results){
75 dojo.forEach(results, function(result){