Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/savsgio/workerpool
Lightweight and fast worker pool with generics support.
https://github.com/savsgio/workerpool
go golang tool utils worker-pool
Last synced: about 1 month ago
JSON representation
Lightweight and fast worker pool with generics support.
- Host: GitHub
- URL: https://github.com/savsgio/workerpool
- Owner: savsgio
- License: apache-2.0
- Created: 2022-05-30T13:05:10.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-04T11:32:53.000Z (9 months ago)
- Last Synced: 2024-06-19T23:14:47.380Z (5 months ago)
- Topics: go, golang, tool, utils, worker-pool
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# workerpool
[![Test status](https://github.com/savsgio/workerpool/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/savsgio/workerpool/actions?workflow=test)
[![Go Report Card](https://goreportcard.com/badge/github.com/savsgio/workerpool)](https://goreportcard.com/report/github.com/savsgio/workerpool)
[![GoDev](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/savsgio/workerpool)Lightweight and fast worker pool with generics support.
Go version: >=1.18
Based on: [valyala/fasthttp/workerpool.go](https://github.com/valyala/fasthttp)
## Example:
```go
type Foo struct {
A int
B int
}wg := sync.WaitGroup{}
handler := func(args Foo) {
log.Println(args.A + args.B)
wg.Done()
}wp := New(
Config{
MaxWorkersCount: 100,
MaxIdleWorkerDuration: 5 * time.Second,
},
handler,
)for i := 0; i < 10; i++ {
wg.Add(1)
wp.Exec(Foo{A: i, B: i + 1})
}wg.Wait()
```