-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPromise.js
62 lines (51 loc) · 1.03 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
57
58
59
60
61
62
Ext('Ext.more') // for Ext.group()
class EPromise extends Promise {
then(f, c, scope) {
// .then(f, scope)
if ('function' != typeof c && c) {
return this.then(f, undefined, c)
}
if (scope) {
return super.then(
f && ((...args) => { f.apply(scope, args) })
,c && ((...args) => { c.apply(scope, args) })
)
}
return super.then(f, c)
}
catch(f, scope) {
return this.then(undefined, f, scope)
}
static delay(num, ...args) {
return new this(p => {
setTimeout(() => { p(...args) }, num)
})
}
static resolve(...args) {
return new this((p,f) => {
p(...args)
})
}
static reject(...args) {
return new this((p,f) => {
f(...args)
})
}
static map(keys, ...args) {
return this.allSettled(args).then(x => {
return Ext.group(keys, x)
})
}
}
class Future {
constructor() {
const p = new Ext.Promise((resolve, reject) => {
this.resolve = resolve
this.reject = reject
})
this.then = p.then.bind(p)
this.catch = p.catch.bind(p)
}
}
Ext.Promise = EPromise
Ext.Future = Future