Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.require("dojo.Deferred");
12
dojo.provide("dojo.DeferredList");
13
dojo.DeferredList = function (list, fireOnOneCallback, fireOnOneErrback, consumeErrors, canceller) {
14
	this.list = list;
15
	this.resultList = new Array(this.list.length);
16
	this.chain = [];
17
	this.id = this._nextId();
18
	this.fired = -1;
19
	this.paused = 0;
20
	this.results = [null, null];
21
	this.canceller = canceller;
22
	this.silentlyCancelled = false;
23
	if (this.list.length === 0 && !fireOnOneCallback) {
24
		this.callback(this.resultList);
25
	}
26
	this.finishedCount = 0;
27
	this.fireOnOneCallback = fireOnOneCallback;
28
	this.fireOnOneErrback = fireOnOneErrback;
29
	this.consumeErrors = consumeErrors;
30
	var index = 0;
31
	var _this = this;
32
	dojo.lang.forEach(this.list, function (d) {
33
		var _index = index;
34
		d.addCallback(function (r) {
35
			_this._cbDeferred(_index, true, r);
36
		});
37
		d.addErrback(function (r) {
38
			_this._cbDeferred(_index, false, r);
39
		});
40
		index++;
41
	});
42
};
43
dojo.inherits(dojo.DeferredList, dojo.Deferred);
44
dojo.lang.extend(dojo.DeferredList, {_cbDeferred:function (index, succeeded, result) {
45
	this.resultList[index] = [succeeded, result];
46
	this.finishedCount += 1;
47
	if (this.fired !== 0) {
48
		if (succeeded && this.fireOnOneCallback) {
49
			this.callback([index, result]);
50
		} else {
51
			if (!succeeded && this.fireOnOneErrback) {
52
				this.errback(result);
53
			} else {
54
				if (this.finishedCount == this.list.length) {
55
					this.callback(this.resultList);
56
				}
57
			}
58
		}
59
	}
60
	if (!succeeded && this.consumeErrors) {
61
		result = null;
62
	}
63
	return result;
64
}, gatherResults:function (deferredList) {
65
	var d = new dojo.DeferredList(deferredList, false, true, false);
66
	d.addCallback(function (results) {
67
		var ret = [];
68
		for (var i = 0; i < results.length; i++) {
69
			ret.push(results[i][1]);
70
		}
71
		return ret;
72
	});
73
	return d;
74
}});
75