Subversion Repositories Applications.papyrus

Rev

Rev 1422 | Details | Compare with Previous | 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
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.require("dojo.Deferred");
14
dojo.provide("dojo.DeferredList");
15
dojo.DeferredList = function (list, fireOnOneCallback, fireOnOneErrback, consumeErrors, canceller) {
16
	this.list = list;
17
	this.resultList = new Array(this.list.length);
18
	this.chain = [];
19
	this.id = this._nextId();
20
	this.fired = -1;
21
	this.paused = 0;
22
	this.results = [null, null];
23
	this.canceller = canceller;
24
	this.silentlyCancelled = false;
25
	if (this.list.length === 0 && !fireOnOneCallback) {
26
		this.callback(this.resultList);
27
	}
28
	this.finishedCount = 0;
29
	this.fireOnOneCallback = fireOnOneCallback;
30
	this.fireOnOneErrback = fireOnOneErrback;
31
	this.consumeErrors = consumeErrors;
32
	var index = 0;
33
	var _this = this;
34
	dojo.lang.forEach(this.list, function (d) {
35
		var _index = index;
36
		d.addCallback(function (r) {
37
			_this._cbDeferred(_index, true, r);
38
		});
39
		d.addErrback(function (r) {
40
			_this._cbDeferred(_index, false, r);
41
		});
42
		index++;
43
	});
44
};
45
dojo.inherits(dojo.DeferredList, dojo.Deferred);
46
dojo.lang.extend(dojo.DeferredList, {_cbDeferred:function (index, succeeded, result) {
47
	this.resultList[index] = [succeeded, result];
48
	this.finishedCount += 1;
49
	if (this.fired !== 0) {
50
		if (succeeded && this.fireOnOneCallback) {
51
			this.callback([index, result]);
52
		} else {
53
			if (!succeeded && this.fireOnOneErrback) {
54
				this.errback(result);
55
			} else {
56
				if (this.finishedCount == this.list.length) {
57
					this.callback(this.resultList);
58
				}
59
			}
60
		}
61
	}
62
	if (!succeeded && this.consumeErrors) {
63
		result = null;
64
	}
65
	return result;
66
}, gatherResults:function (deferredList) {
67
	var d = new dojo.DeferredList(deferredList, false, true, false);
68
	d.addCallback(function (results) {
69
		var ret = [];
70
		for (var i = 0; i < results.length; i++) {
71
			ret.push(results[i][1]);
72
		}
73
		return ret;
74
	});
75
	return d;
76
}});
77