From 360a5be5f72e41074993e1bd11d541da6301c826 Mon Sep 17 00:00:00 2001 From: andy pan Date: Mon, 2 Jul 2018 14:45:25 +0800 Subject: [PATCH] update example codes in readme --- README.md | 11 +++++++---- README_ZH.md | 11 +++++++---- examples/main.go | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6469519..341c21b 100644 --- a/README.md +++ b/README.md @@ -44,16 +44,16 @@ import ( "fmt" "sync" "sync/atomic" + "time" "github.com/panjf2000/ants" - "time" ) var sum int32 func myFunc(i interface{}) error { - n := i.(int) - atomic.AddInt32(&sum, int32(n)) + n := i.(int32) + atomic.AddInt32(&sum, n) fmt.Printf("run with %d\n", n) return nil } @@ -65,6 +65,8 @@ func demoFunc() error { } func main() { + defer ants.Release() + runTimes := 1000 // use the common pool @@ -88,10 +90,11 @@ func main() { wg.Done() return nil }) + defer p.Release() // submit tasks for i := 0; i < runTimes; i++ { wg.Add(1) - p.Serve(i) + p.Serve(int32(i)) } wg.Wait() fmt.Printf("running goroutines: %d\n", p.Running()) diff --git a/README_ZH.md b/README_ZH.md index a50e954..245db02 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -45,16 +45,16 @@ import ( "fmt" "sync" "sync/atomic" + "time" "github.com/panjf2000/ants" - "time" ) var sum int32 func myFunc(i interface{}) error { - n := i.(int) - atomic.AddInt32(&sum, int32(n)) + n := i.(int32) + atomic.AddInt32(&sum, n) fmt.Printf("run with %d\n", n) return nil } @@ -66,6 +66,8 @@ func demoFunc() error { } func main() { + defer ants.Release() + runTimes := 1000 // use the common pool @@ -89,10 +91,11 @@ func main() { wg.Done() return nil }) + defer p.Release() // submit tasks for i := 0; i < runTimes; i++ { wg.Add(1) - p.Serve(i) + p.Serve(int32(i)) } wg.Wait() fmt.Printf("running goroutines: %d\n", p.Running()) diff --git a/examples/main.go b/examples/main.go index bbf7457..53ef719 100644 --- a/examples/main.go +++ b/examples/main.go @@ -26,9 +26,9 @@ import ( "fmt" "sync" "sync/atomic" + "time" "github.com/panjf2000/ants" - "time" ) var sum int32