From af159c3f47aa8e61a5866d6b581a2434f450a5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=B0=8F=E5=86=9B?= Date: Mon, 16 Sep 2019 17:21:27 +0800 Subject: [PATCH] add workpool --- README.md | 16 ++++++++-------- README_cn.md | 16 ++++++++-------- main.go | 4 ++-- {workerpool => workpool}/def.go | 2 +- workerpool/workerpool.go => workpool/workpool.go | 8 +++----- .../workpool_test.go | 2 +- 6 files changed, 23 insertions(+), 25 deletions(-) rename {workerpool => workpool}/def.go (97%) rename workerpool/workerpool.go => workpool/workpool.go (96%) rename workerpool/workerpool_test.go => workpool/workpool_test.go (99%) diff --git a/README.md b/README.md index ec9d6cf..f3fb51e 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,11 @@ import ( "fmt" "time" - "github.com/xxjwxc/gowp/workerpool" + "github.com/xxjwxc/gowp/workpool" ) func main() { - wp := workerpool.New(10) //Set the maximum number of threads,设置最大线程数 + wp := workpool.New(10) //Set the maximum number of threads,设置最大线程数 for i := 0; i < 20; i++ { //开启20个请求 ii := i wp.Do(func() error { @@ -47,11 +47,11 @@ import ( "fmt" "time" - "github.com/xxjwxc/gowp/workerpool" + "github.com/xxjwxc/gowp/workpool" ) func main() { - wp := workerpool.New(10) //Set the maximum number of threads,设置最大线程数 + wp := workpool.New(10) //Set the maximum number of threads,设置最大线程数 for i := 0; i < 20; i++ { ii := i wp.Do(func() error { @@ -84,11 +84,11 @@ import ( "fmt" "time" - "github.com/xxjwxc/gowp/workerpool" + "github.com/xxjwxc/gowp/workpool" ) func main() { - wp := workerpool.New(5) //Set the maximum number of threads,设置最大线程数 + wp := workpool.New(5) //Set the maximum number of threads,设置最大线程数 for i := 0; i < 10; i++ { // ii := i wp.Do(func() error { @@ -116,11 +116,11 @@ import ( "fmt" "time" - "github.com/xxjwxc/gowp/workerpool" + "github.com/xxjwxc/gowp/workpool" ) func main() { - wp := workerpool.New(5) //Set the maximum number of threads,设置最大线程数 + wp := workpool.New(5) //Set the maximum number of threads,设置最大线程数 for i := 0; i < 10; i++ { ii := i wp.DoWait(func() error { diff --git a/README_cn.md b/README_cn.md index e9a0bf3..f45184d 100644 --- a/README_cn.md +++ b/README_cn.md @@ -15,11 +15,11 @@ import ( "fmt" "time" - "github.com/xxjwxc/gowp/workerpool" + "github.com/xxjwxc/gowp/workpool" ) func main() { - wp := workerpool.New(10) //设置最大线程数 + wp := workpool.New(10) //设置最大线程数 for i := 0; i < 20; i++ { //开启20个请求 ii := i wp.Do(func() error { @@ -45,11 +45,11 @@ import ( "fmt" "time" - "github.com/xxjwxc/gowp/workerpool" + "github.com/xxjwxc/gowp/workpool" ) func main() { - wp := workerpool.New(10) //设置最大线程数 + wp := workpool.New(10) //设置最大线程数 for i := 0; i < 20; i++ { //开启20个请求 ii := i wp.Do(func() error { @@ -82,11 +82,11 @@ import ( "fmt" "time" - "github.com/xxjwxc/gowp/workerpool" + "github.com/xxjwxc/gowp/workpool" ) func main() { - wp := workerpool.New(5) //设置最大线程数 + wp := workpool.New(5) //设置最大线程数 for i := 0; i < 10; i++ { //开启20个请求 // ii := i wp.Do(func() error { @@ -114,11 +114,11 @@ import ( "fmt" "time" - "github.com/xxjwxc/gowp/workerpool" + "github.com/xxjwxc/gowp/workpool" ) func main() { - wp := workerpool.New(5) //设置最大线程数 + wp := workpool.New(5) //设置最大线程数 for i := 0; i < 10; i++ { //开启20个请求 ii := i wp.DoWait(func() error { diff --git a/main.go b/main.go index 344716f..ff94101 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,12 @@ package main import ( "fmt" - "github.com/xxjwxc/gowp/workerpool" + "github.com/xxjwxc/gowp/workpool" "github.com/xxjwxc/public/errors" ) func tets() { - wp := workerpool.New(5) //设置最大线程数 + wp := workpool.New(5) //设置最大线程数 wp.DoWait(func() error { for j := 0; j < 10; j++ { fmt.Println(fmt.Sprintf("%v->\t%v", 000, j)) diff --git a/workerpool/def.go b/workpool/def.go similarity index 97% rename from workerpool/def.go rename to workpool/def.go index aabeeb7..0eaf0a9 100644 --- a/workerpool/def.go +++ b/workpool/def.go @@ -1,4 +1,4 @@ -package workerpool +package workpool import ( "sync" diff --git a/workerpool/workerpool.go b/workpool/workpool.go similarity index 96% rename from workerpool/workerpool.go rename to workpool/workpool.go index 399fc86..1435042 100644 --- a/workerpool/workerpool.go +++ b/workpool/workpool.go @@ -1,4 +1,4 @@ -package workerpool +package workpool import ( "context" @@ -6,8 +6,6 @@ import ( "time" "github.com/xxjwxc/public/myqueue" - - "github.com/xxjwxc/public/mylog" ) //New 注册工作池,并设置最大并发数 @@ -127,7 +125,7 @@ func (p *WorkerPool) loop(maxWorkersCount int) { case <-ct.Done(): p.errChan <- ct.Err() //if atomic.LoadInt32(&p.closed) != 1 { - mylog.Error(ct.Err()) + //mylog.Error(ct.Err()) atomic.StoreInt32(&p.closed, 1) cancel() case <-closed: @@ -141,7 +139,7 @@ func (p *WorkerPool) loop(maxWorkersCount int) { select { case p.errChan <- err: //if atomic.LoadInt32(&p.closed) != 1 { - mylog.Error(err) + //mylog.Error(err) atomic.StoreInt32(&p.closed, 1) default: } diff --git a/workerpool/workerpool_test.go b/workpool/workpool_test.go similarity index 99% rename from workerpool/workerpool_test.go rename to workpool/workpool_test.go index 0a53341..7d9ae2f 100644 --- a/workerpool/workerpool_test.go +++ b/workpool/workpool_test.go @@ -1,4 +1,4 @@ -package workerpool +package workpool import ( "fmt"