From 917dfb037facbc6e81f55d8a7bab82c42fc32616 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Fri, 7 Dec 2018 00:33:43 +0800 Subject: [PATCH] update some annotations --- README.md | 24 ++++++++++++------------ README_ZH.md | 18 +++++++++--------- examples/main.go | 8 ++++---- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 345f9cb..4d64e53 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ func main() { runTimes := 1000 - // Uses the common pool + // Use the common pool var wg sync.WaitGroup for i := 0; i < runTimes; i++ { wg.Add(1) @@ -81,14 +81,14 @@ func main() { fmt.Printf("running goroutines: %d\n", ants.Running()) fmt.Printf("finish all tasks.\n") - // Uses the pool with a function, - // sets 10 to the size of goroutine pool and 1 second for expired duration + // Use the pool with a function, + // set 10 to the size of goroutine pool and 1 second for expired duration p, _ := ants.NewPoolWithFunc(10, func(i interface{}) { myFunc(i) wg.Done() }) defer p.Release() - // Submits tasks + // Submit tasks for i := 0; i < runTimes; i++ { wg.Add(1) p.Serve(int32(i)) @@ -141,7 +141,7 @@ func main() { request := &Request{Param: param, Result: make(chan []byte)} - // Throttles the requests with ants pool. This process is asynchronous and + // Throttle the requests traffic with ants pool. This process is asynchronous and // you can receive a result from the channel defined outside. if err := pool.Serve(request); err != nil { http.Error(w, "throttle limit error", http.StatusInternalServerError) @@ -154,28 +154,28 @@ func main() { } ``` -## Submits tasks +## Submit tasks Tasks can be submitted by calling `ants.Submit(func())` ```go ants.Submit(func(){}) ``` -## Customizes limited pool +## Customize limited pool `ants` also supports customizing limited pool. You can use the `NewPool` method to create a pool with the given capacity, as following: ``` go -// Sets 10000 the size of goroutine pool +// Set 10000 the size of goroutine pool p, _ := ants.NewPool(10000) -// Submits a task +// Submit a task p.Submit(func(){}) ``` -## Tunes pool capacity +## Tune pool capacity You can change `ants` pool capacity at any time with `ReSize(int)`: ``` go -pool.ReSize(1000) // Tunes its capacity to 1000 -pool.ReSize(100000) // Tunes its capacity to 100000 +pool.ReSize(1000) // Tune its capacity to 1000 +pool.ReSize(100000) // Tune its capacity to 100000 ``` Don't worry about the synchronous problems in this case, this method is thread-safe. diff --git a/README_ZH.md b/README_ZH.md index c9b9691..6eebf50 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -67,7 +67,7 @@ func main() { runTimes := 1000 - // Uses the common pool + // Use the common pool var wg sync.WaitGroup for i := 0; i < runTimes; i++ { wg.Add(1) @@ -80,14 +80,14 @@ func main() { fmt.Printf("running goroutines: %d\n", ants.Running()) fmt.Printf("finish all tasks.\n") - // Uses the pool with a function, - // sets 10 to the size of goroutine pool and 1 second for expired duration + // Use the pool with a function, + // set 10 to the size of goroutine pool and 1 second for expired duration p, _ := ants.NewPoolWithFunc(10, func(i interface{}) { myFunc(i) wg.Done() }) defer p.Release() - // Submits tasks + // Submit tasks for i := 0; i < runTimes; i++ { wg.Add(1) p.Serve(int32(i)) @@ -140,7 +140,7 @@ func main() { request := &Request{Param: param, Result: make(chan []byte)} - // Throttles the requests with ants pool. This process is asynchronous and + // Throttle the requests traffic with ants pool. This process is asynchronous and // you can receive a result from the channel defined outside. if err := pool.Serve(request); err != nil { http.Error(w, "throttle limit error", http.StatusInternalServerError) @@ -163,9 +163,9 @@ ants.Submit(func(){}) `ants`支持实例化使用者自己的一个 Pool ,指定具体的池容量;通过调用 `NewPool` 方法可以实例化一个新的带有指定容量的 Pool ,如下: ``` go -// Sets 10000 the size of goroutine pool +// Set 10000 the size of goroutine pool p, _ := ants.NewPool(10000) -// Submits a task +// Submit a task p.Submit(func(){}) ``` @@ -173,8 +173,8 @@ p.Submit(func(){}) 需要动态调整协程池容量可以通过调用`ReSize(int)`: ``` go -pool.ReSize(1000) // Tuning its capacity to 1000 -pool.ReSize(100000) // Tuning its capacity to 100000 +pool.ReSize(1000) // Tune its capacity to 1000 +pool.ReSize(100000) // Tune its capacity to 100000 ``` 该方法是线程安全的。 diff --git a/examples/main.go b/examples/main.go index a45eb41..23a1ca3 100644 --- a/examples/main.go +++ b/examples/main.go @@ -49,7 +49,7 @@ func main() { runTimes := 1000 - // Uses the common pool + // Use the common pool var wg sync.WaitGroup for i := 0; i < runTimes; i++ { wg.Add(1) @@ -62,14 +62,14 @@ func main() { fmt.Printf("running goroutines: %d\n", ants.Running()) fmt.Printf("finish all tasks.\n") - // Uses the pool with a function, - // sets 10 to the size of goroutine pool and 1 second for expired duration + // Use the pool with a function, + // set 10 to the size of goroutine pool and 1 second for expired duration p, _ := ants.NewPoolWithFunc(10, func(i interface{}) { myFunc(i) wg.Done() }) defer p.Release() - // Submits tasks + // Submit tasks for i := 0; i < runTimes; i++ { wg.Add(1) p.Serve(int32(i))