forked from xxjwxc/gowp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (37 loc) · 805 Bytes
/
main.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 main
import (
"fmt"
"github.com/xxjwxc/gowp/workpool"
"github.com/xxjwxc/public/errors"
)
func tets() {
wp := workpool.New(5) //设置最大线程数
wp.DoWait(func() error {
for j := 0; j < 10; j++ {
fmt.Println(fmt.Sprintf("%v->\t%v", 000, j))
}
return nil
//time.Sleep(1 * time.Second)
//return errors.New("my test err")
})
for i := 0; i < 10; i++ { //开启10个请求
ii := i
wp.Do(func() error {
for j := 0; j < 5; j++ { //每次打印0-10的值
fmt.Println(fmt.Sprintf("%v->\t%v", ii, j))
if ii == 1 {
return errors.Cause(errors.New("my test err")) //有err 立即返回
}
}
return nil
})
fmt.Println(wp.IsDone())
}
wp.Wait()
fmt.Println(wp.IsDone())
fmt.Println(wp.IsClosed())
fmt.Println("down")
}
func main() {
tets()
}