Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
谢小军 authored and 谢小军 committed Sep 15, 2019
1 parent 324474a commit 4254ac6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
25 changes: 20 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@ package main

import (
"fmt"
"time"

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

func main() {
wp := workerpool.New(5) //设置最大线程数
func tets() {
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 @@ -24,6 +36,9 @@ func main() {

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

fmt.Println(wp.IsClosed())
fmt.Println("down")
}
func main() {
tets()
}
35 changes: 1 addition & 34 deletions main_test.go
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()
}

0 comments on commit 4254ac6

Please sign in to comment.