Documentation
¶
Overview ¶
Package gopool provides Add, Done and Wait methods just like sync.WaitGroup would do. On top of that, a max concurrency is applied so that the number of goroutines stays under control
Example ¶
package main
import (
"log"
"time"
"github.com/aherve/gopool"
)
func main() {
pool := gopool.NewPool(3) // creates pool with limited concurrency of 3
for i := 0; i < 10; i++ {
pool.Add(1) // This will pause until a slot is available
go work(i, pool)
}
pool.Wait()
log.Println("All Done !")
}
func work(i int, pool *gopool.GoPool) {
defer pool.Done() // just like with sync.WaitGroup
log.Printf("working hard on %v", i)
time.Sleep(time.Second)
log.Printf("%v is done", i)
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.