From 8dd9d3e75b470230368feb729eff6383bb5e8959 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 2 Feb 2019 10:27:28 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AC=20Replace=20anonymous=20function?= =?UTF-8?q?=20with=20explicit=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/main.go b/examples/main.go index 0d28879..bbd2b1e 100644 --- a/examples/main.go +++ b/examples/main.go @@ -51,19 +51,20 @@ func main() { // 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()