-
Notifications
You must be signed in to change notification settings - Fork 1
/
immediately_fulfilled.go
43 lines (34 loc) · 987 Bytes
/
immediately_fulfilled.go
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
package promises
type immediatelyFulfilled struct {
fulfilled chan PromiseResult
rejected chan PromiseResult
}
func (promise *immediatelyFulfilled) onFulfilled() chan PromiseResult {
return promise.fulfilled
}
func (promise *immediatelyFulfilled) onRejected() chan PromiseResult {
return promise.rejected
}
func (promise *immediatelyFulfilled) Then(next func(PromiseResult) Promise) Promise {
return then(promise, next)
}
func (promise *immediatelyFulfilled) Fail(next func(PromiseResult) Promise) Promise {
return fail(promise, next)
}
func (promise *immediatelyFulfilled) Done() {
done(promise)
}
func newImmediatelyFulfilled(value PromiseResult) *immediatelyFulfilled {
promise := &immediatelyFulfilled{
fulfilled: make(chan PromiseResult, 1),
rejected: make(chan PromiseResult, 1),
}
promise.fulfilled <- value
return promise
}
func Fulfil(value PromiseResult) Promise {
return newImmediatelyFulfilled(value)
}
func Empty() Promise {
return Fulfil(nil)
}