-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync_test.go
More file actions
63 lines (57 loc) · 1.2 KB
/
async_test.go
File metadata and controls
63 lines (57 loc) · 1.2 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
54
55
56
57
58
59
60
61
62
63
package vgo
import (
"fmt"
"strconv"
"testing"
)
func doAsync() *Async {
return &Async{
Callback: func() interface{} {
return 30
},
}
}
func TestAsync(t *testing.T) {
async := doAsync()
result := Await(async)
fmt.Println("Result async:", strconv.Itoa(result.(int))) // Output: Result async: 30
}
func TestDeferred(t *testing.T) {
deferred := &Deferred{
Callback: func() interface{} {
return 50
},
}
result := deferred.Await()
fmt.Println("Result deferred:", strconv.Itoa(result.(int))) // Output: Result deferred: 50
}
func TestDeferredAll(t *testing.T) {
deferred := &Deferred{}
result := deferred.All(
func() interface{} {
return 10
},
func() interface{} {
return 20
},
func() interface{} {
return 30
},
).Await()
fmt.Println("Result deferred all:", result) // Output: Result deferred all: [10 20 30]
}
func TestDeferredAny(t *testing.T) {
deferred := &Deferred{}
result := deferred.Any(
func() interface{} {
return 10
},
func() interface{} {
return 20
},
func() interface{} {
return 30
},
).Await()
fmt.Println("Result deferred any:", result) // Output: Result deferred any: 10
}