forked from xxjwxc/gowp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
谢小军
authored and
谢小军
committed
Sep 15, 2019
1 parent
324474a
commit 4254ac6
Showing
2 changed files
with
21 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/xxjwxc/gowp/workerpool" | ||
"github.com/xxjwxc/public/errors" | ||
) | ||
|
||
func TestMain(t *testing.T) { | ||
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)) | ||
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") | ||
tets() | ||
} |