Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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