forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync.es6
More file actions
53 lines (42 loc) · 1.18 KB
/
async.es6
File metadata and controls
53 lines (42 loc) · 1.18 KB
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
import {int, global} from 'angular2/src/facade/lang';
import {List} from 'angular2/src/facade/collection';
export var Promise = global.Promise;
export class PromiseWrapper {
static resolve(obj):Promise {
return Promise.resolve(obj);
}
static reject(obj):Promise {
return Promise.reject(obj);
}
// Note: We can't rename this method into `catch`, as this is not a valid
// method name in Dart.
static catchError(promise:Promise, onError:Function):Promise {
return promise.catch(onError);
}
static all(promises:List):Promise {
if (promises.length == 0) return Promise.resolve([]);
return Promise.all(promises);
}
static then(promise:Promise, success:Function, rejection:Function):Promise {
return promise.then(success, rejection);
}
static completer() {
var resolve;
var reject;
var p = new Promise(function(res, rej) {
resolve = res;
reject = rej;
});
return {
promise: p,
resolve: resolve,
reject: reject
};
}
static setTimeout(fn:Function, millis:int) {
global.setTimeout(fn, millis);
}
static isPromise(maybePromise):boolean {
return maybePromise instanceof Promise;
}
}