Skip to content

Commit

Permalink
update some annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Dec 6, 2018
1 parent 4237f29 commit 917dfb0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -163,18 +163,18 @@ 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(){})
```

## 动态调整协程池容量
需要动态调整协程池容量可以通过调用`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
```

该方法是线程安全的。
Expand Down
8 changes: 4 additions & 4 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down

0 comments on commit 917dfb0

Please sign in to comment.