-
Notifications
You must be signed in to change notification settings - Fork 0
/
async_parallel_test.go
44 lines (40 loc) · 978 Bytes
/
async_parallel_test.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
package async
import (
"errors"
"fmt"
"testing"
"time"
)
func TestParallel(t *testing.T) {
p := Parallel()
p.AddFuncs(Func{Tag: "a", F: func() error {
fmt.Println("a ", time.Now().UnixNano())
return errors.New("a's error")
}}, Func{Tag: "b", F: func() error {
fmt.Println("b ", time.Now().UnixNano())
return errors.New("b's error")
}}, Func{Tag: "c", F: func() error {
time.Sleep(5 * time.Second)
fmt.Println("c ", time.Now().UnixNano())
return errors.New("c's error")
}}, Func{Tag: "d", F: func() error {
fmt.Println("d ", time.Now().UnixNano())
fmt.Println("d done")
return nil
}})
p.SetTimeout(time.Millisecond)
err := p.Run()
fmt.Printf("Parallel err: %+v\n", err)
p.AddFuncs(Func{"lily", func() error {
fmt.Println("lily")
return nil
}}, Func{"lucy", func() error {
fmt.Println("lucy")
return nil
}}, Func{"robin", func() error {
fmt.Println("robin")
return nil
}})
err = p.Run()
fmt.Printf("PPPPP err: %+v\n", err)
}