https://github.com/rocketbitz/pool
a simple worker pool for gophers
https://github.com/rocketbitz/pool
concurrency concurrent-programming go golang gopher goroutine multithreading performance pool pooling simple threading worker worker-pool workers
Last synced: 5 months ago
JSON representation
a simple worker pool for gophers
- Host: GitHub
- URL: https://github.com/rocketbitz/pool
- Owner: rocketbitz
- License: mit
- Created: 2019-05-25T02:40:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-08-21T03:01:16.000Z (10 months ago)
- Last Synced: 2025-08-21T04:42:23.420Z (10 months ago)
- Topics: concurrency, concurrent-programming, go, golang, gopher, goroutine, multithreading, performance, pool, pooling, simple, threading, worker, worker-pool, workers
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pool [](https://circleci.com/gh/rocketbitz/pool/tree/master)
a simple worker pool for gophers
# installation
as with all other go packages, you know what to do:
```
go get github.com/rocketbitz/pool
```
# usage
this worker pool package was designed to be straightforward, specifically because I found others to be unnecessarily complex. here's an example:
```go
package main
import (
"fmt"
"github.com/rocketbitz/pool"
)
func main() {
numWorkers := 10
jobToRun := func(input interface{}) {
fmt.Println("let's do a job on this input: ", input)
}
jobStartCallback := pool.Callback{
Event: pool.JobStart,
Func: func() {
fmt.Println("we're starting a job...")
},
}
jobEndCallback := pool.Callback{
Event: pool.JobEnd,
Func: func() {
fmt.Println("we've finished a job.")
},
}
p := pool.New(
numWorkers,
jobToRun,
jobStartCallback,
jobEndCallback,
)
c := make(chan interface{})
go p.Work(c)
for i := 0; i < 100; i++ {
c <- "hello, gophers"
}
close(c)
p.Wait()
}
```
hopefully that example makes sense to you. note that the callback argument to `New()` is variadic, so register as many callbacks as your heart desires. oh, one more thing, if you forget a callback when you declare the pool, you can always register one later like so:
```go
p.RegisterCallback(
Callback{
Event: JobEnd,
Func: func() { fmt.Println("i'm a forgetful gopher") },
},
)
```
# contribute
pr's are welcome. if they're awesome, they'll get reviewed and merged. if they're not, they'll get reviewed and closed, hopefully with a kind comment as to the reason.
# license
[MIT](https://github.com/rocketbitz/pool/blob/master/LICENSE) ...move along, move along.