UNPKG

1.75 kBJavaScriptView Raw
1"use strict";
2var PromiseCompleter = (function () {
3 function PromiseCompleter() {
4 var _this = this;
5 this.promise = new Promise(function (res, rej) {
6 _this.resolve = res;
7 _this.reject = rej;
8 });
9 }
10 return PromiseCompleter;
11}());
12exports.PromiseCompleter = PromiseCompleter;
13var PromiseWrapper = (function () {
14 function PromiseWrapper() {
15 }
16 PromiseWrapper.resolve = function (obj) { return Promise.resolve(obj); };
17 PromiseWrapper.reject = function (obj, _) { return Promise.reject(obj); };
18 // Note: We can't rename this method into `catch`, as this is not a valid
19 // method name in Dart.
20 PromiseWrapper.catchError = function (promise, onError) {
21 return promise.catch(onError);
22 };
23 PromiseWrapper.all = function (promises) {
24 if (promises.length == 0)
25 return Promise.resolve([]);
26 return Promise.all(promises);
27 };
28 PromiseWrapper.then = function (promise, success, rejection) {
29 return promise.then(success, rejection);
30 };
31 PromiseWrapper.wrap = function (computation) {
32 return new Promise(function (res, rej) {
33 try {
34 res(computation());
35 }
36 catch (e) {
37 rej(e);
38 }
39 });
40 };
41 PromiseWrapper.scheduleMicrotask = function (computation) {
42 PromiseWrapper.then(PromiseWrapper.resolve(null), computation, function (_) { });
43 };
44 PromiseWrapper.isPromise = function (obj) { return obj instanceof Promise; };
45 PromiseWrapper.completer = function () { return new PromiseCompleter(); };
46 return PromiseWrapper;
47}());
48exports.PromiseWrapper = PromiseWrapper;
49//# sourceMappingURL=promise.js.map
\No newline at end of file