https://github.com/yale8848/gorpool
Simple Goroutine pool
https://github.com/yale8848/gorpool
golang goroutine pool routines
Last synced: 2 months ago
JSON representation
Simple Goroutine pool
- Host: GitHub
- URL: https://github.com/yale8848/gorpool
- Owner: yale8848
- License: mit
- Created: 2018-01-07T13:33:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-11T03:22:56.000Z (almost 6 years ago)
- Last Synced: 2025-04-30T18:07:56.519Z (2 months ago)
- Topics: golang, goroutine, pool, routines
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 36
- Watchers: 3
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gorpool
Simple Goroutine pool
# How to use
```
go get github.com/yale8848/[email protected]
```## Simple example
```go
package main
import (
"github.com/yale8848/gorpool"
"time"
"fmt"
)func main() {
// workerNum is worker number of goroutine pool ,one worker have one goroutine ,
// jobNum is job number of job pool
p := gorpool.NewPool(5, 10).
Start()
defer p.StopAll()
for i := 0; i < 100; i++ {
count := i
p.AddJob(func() {
time.Sleep(10 * time.Millisecond)
fmt.Printf("%d\r\n", count)
})}
time.Sleep(2 * time.Second)
}```
## WaitForAll
```go
package main
import (
"fmt"
"github.com/yale8848/gorpool"
"time"
)func main() {
p := gorpool.NewPool(5, 10).
Start().
EnableWaitForAll(true)
for i := 0; i < 100; i++ {
count := i
p.AddJob(func() {
time.Sleep(10 * time.Millisecond)
fmt.Printf("%d\r\n", count)
})
}
p.WaitForAll()
p.StopAll()
}```
## SetIdleDuration
After set idle duration , the worker will stop it worker go routine
```go
package main
import (
"fmt"
"github.com/yale8848/gorpool"
"time"
)func main() {
p := gorpool.NewPool(5, 10).
SetIdleDuration(3 * time.Second).
Start().
EnableWaitForAll(true)
for i := 0; i < 100; i++ {
count := i
p.AddJob(func() {
time.Sleep(5 * time.Second)
fmt.Printf("%d\r\n", count)
})
}
p.WaitForAll()
p.StopAll()
}```
## Doc
[gorpool doc](https://godoc.org/github.com/yale8848/gorpool)