https://github.com/ykhrustalev/goroutinepool
A helper to run goroutines in a pool just like in java's or python's pools
https://github.com/ykhrustalev/goroutinepool
golang goroutine goroutine-pool pool
Last synced: 3 months ago
JSON representation
A helper to run goroutines in a pool just like in java's or python's pools
- Host: GitHub
- URL: https://github.com/ykhrustalev/goroutinepool
- Owner: ykhrustalev
- License: mit
- Created: 2018-12-02T00:01:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-19T20:34:56.000Z (over 5 years ago)
- Last Synced: 2024-06-20T17:29:14.996Z (almost 2 years ago)
- Topics: golang, goroutine, goroutine-pool, pool
- Language: Go
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Goroutinepool
[](https://godoc.org/github.com/ykhrustalev/goroutinepool)
[](https://travis-ci.org/ykhrustalev/goroutinepool)
[](https://goreportcard.com/report/github.com/ykhrustalev/goroutinepool)
Package goroutinepool provides handy functions for running goroutines
concurrently similar to `multiprocess.Pool` in python or
`concurrency.ThreadPoolExecutor` in java.
Example:
```go
ctx := context.Background()
var counter int32
// a simple job to increment a number
increment := func(delta int32) func(context.Context) {
return func(ctx context.Context) {
atomic.AddInt32(&counter, delta)
}
}
// jobs
fns := []func(context.Context){
increment(1),
increment(10),
increment(100),
}
// use two workers
goroutinepool.RunInPool(ctx, 2, fns)
fmt.Println(atomic.LoadInt32(&counter))
// Output:
// 111
```