-
Notifications
You must be signed in to change notification settings - Fork 1
/
Promise.js
56 lines (56 loc) · 2.14 KB
/
Promise.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
define(["require", "exports", 'dojo/Deferred', 'dojo/promise/Promise', 'dojo/_base/lang', 'dojo/promise/all'], function (require, exports, Deferred, DojoPromise, lang, whenAll) {
var Promise = (function () {
function Promise(initializer) {
var canceler;
var dfd = new Deferred(function (reason) {
return canceler && canceler(reason);
});
try {
initializer(function (value) {
if (value && value.then) {
var promise = value;
promise.then(lang.hitch(dfd, 'resolve'), lang.hitch(dfd, 'reject'), lang.hitch(dfd, 'progress'));
if (promise.cancel) {
canceler = (function (oldCanceler) {
return function (reason) {
promise.cancel(reason);
oldCanceler && oldCanceler(reason);
};
})(canceler);
}
}
else {
dfd.resolve(value);
}
}, lang.hitch(dfd, 'reject'), lang.hitch(dfd, 'progress'), function (_canceler) {
canceler = _canceler;
});
}
catch (error) {
dfd.reject(error);
}
return dfd.promise;
}
Promise.reject = function (error) {
var dfd = new Deferred();
dfd.reject(error);
return dfd.promise;
};
Promise.resolve = function (value) {
if (value instanceof DojoPromise || value instanceof Promise) {
return value;
}
if (value instanceof Deferred) {
return value.promise;
}
return new Promise(function (resolve) {
resolve(value);
});
};
Promise.all = whenAll;
Promise.Deferred = Deferred;
return Promise;
})();
return Promise;
});
//# sourceMappingURL=_debug/Promise.js.map