Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/youjinp/workerpool
https://github.com/youjinp/workerpool
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/youjinp/workerpool
- Owner: youjinp
- Created: 2020-09-09T06:14:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-02T04:42:57.000Z (over 2 years ago)
- Last Synced: 2024-06-20T07:37:02.017Z (6 months ago)
- Language: Go
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# workerpool
Concurrency limiting goroutine pool. Limits the concurrency of task execution, not the number of tasks queued. Never blocks submitting tasks, no matter how many tasks are queued.
This implementation builds on the repo:
- https://github.com/gammazero/workerpool
Changes made:
- Add context support
- Update task to have an error return value## Example
```go
package mainimport (
"fmt"
"github.com/youjinp/workerpool"
)func main() {
wp := workerpool.New(context.TODO(), 2)
requests := []string{"alpha", "beta", "gamma", "delta", "epsilon"}for _, r := range requests {
r := r
wp.Submit(func() error {
fmt.Println("Handling request:", r)
return nil
})
}if err := wp.Wait(); err != nil {
log.Fatal(err)
}
}
```