From 834c55092178a80dd3088ae7b9ab5c23aa1a74c5 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 2 Feb 2019 10:28:15 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B2=20Update=20example=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 56ec5c9..9c26594 100644 --- a/README.md +++ b/README.md @@ -76,27 +76,28 @@ func main() { runTimes := 1000 - // Use the common pool + // Use the common pool. var wg sync.WaitGroup + syncCalculateSum := func() { + demoFunc() + wg.Done() + } for i := 0; i < runTimes; i++ { wg.Add(1) - ants.Submit(func() { - demoFunc() - wg.Done() - }) + ants.Submit(syncCalculateSum) } wg.Wait() fmt.Printf("running goroutines: %d\n", ants.Running()) fmt.Printf("finish all tasks.\n") // Use the pool with a function, - // set 10 to the size of goroutine pool and 1 second for expired duration + // set 10 to the capacity of goroutine pool and 1 second for expired duration. p, _ := ants.NewPoolWithFunc(10, func(i interface{}) { myFunc(i) wg.Done() }) defer p.Release() - // Submit tasks + // Submit tasks one by one. for i := 0; i < runTimes; i++ { wg.Add(1) p.Serve(int32(i))