-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (33 loc) · 784 Bytes
/
index.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
export class Waiter {
constructor () {
this._private = {}
this.promise = new Promise((resolve, reject) => {
this._private.resolve = resolve
this._private.reject = reject
})
this.then = this.promise.then.bind(this.promise)
this.catch = this.promise.catch.bind(this.promise)
this.settled = false
this.result = null
this.reason = null
this.resolve = this.resolve.bind(this)
this.reject = this.reject.bind(this)
}
resolve (obj) {
if (this.settled) {
return
}
this.settled = true
this.result = obj
this._private.resolve(obj)
}
reject (reason) {
if (this.settled) {
return
}
this.settled = true
this.reason = reason
this._private.reject(reason)
}
}
export default Waiter