-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.go
46 lines (45 loc) · 1.17 KB
/
export.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
44
45
46
package async
func DEV() {
env = dev
}
func PROD() {
env = prod
}
func Resolve(v interface{}) *GoPromise {
if then, ok := isThenable(v); ok {
return Promise(then.Then)
} else if promise, ok := isPromise(v); ok {
return promise
} else {
return &GoPromise{&lock{make(chan int), v, Resolved, false, nil}, nil}
}
}
func Reject(v interface{}) *GoPromise {
return &GoPromise{&lock{make(chan int), v, Rejected, false, nil}, nil}
}
func Do(task AsyncTask, params ...interface{}) *GoPromise {
return Promise(func(resolve, reject Handler) {
resolve(task(params...))
})
}
func Promise(task promiseTask) *GoPromise {
promise := gPromise()
collectTask()
go promise.execPromise(task)
return promise
}
func All(plain *Plain) *GoPromise {
return funcCallWithErrorIntercept(plain.toPromise(), "All")
}
func Race(plain *Plain) *GoPromise {
return funcCallWithErrorIntercept(plain.toPromise(), "Race")
}
func AllSettled(plain *Plain) *GoPromise {
return funcCallWithErrorIntercept(plain.toPromise(), "AllSettled")
}
func Any(plain *Plain) *GoPromise {
return funcCallWithErrorIntercept(plain.toPromise(), "Any")
}
func Wait() {
wg.Wait()
}