Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
谢小军 authored and 谢小军 committed Sep 15, 2019
1 parent d381171 commit 7239ebf
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@ package main
import (
"fmt"
"testing"
"time"

"github.com/xxjwxc/gowp/workerpool"
"github.com/xxjwxc/public/errors"
)

func TestMain(t *testing.T) {
wp := workerpool.New(5) //设置最大线程数
wp := workerpool.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))
time.Sleep(1 * time.Second)
if ii == 1 {
return errors.Cause(errors.New("my test err")) //有err 立即返回
}
}
return nil
})
Expand All @@ -25,6 +37,6 @@ func TestMain(t *testing.T) {

wp.Wait()
fmt.Println(wp.IsDone())

fmt.Println(wp.IsClosed())
fmt.Println("down")
}

0 comments on commit 7239ebf

Please sign in to comment.