https://github.com/limpo1989/taskgo
taskgo is a lightweight task pool in Go
https://github.com/limpo1989/taskgo
pool task-runner taskpool worker-pool
Last synced: about 1 year ago
JSON representation
taskgo is a lightweight task pool in Go
- Host: GitHub
- URL: https://github.com/limpo1989/taskgo
- Owner: limpo1989
- License: apache-2.0
- Created: 2023-08-03T10:07:33.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-07T07:39:17.000Z (almost 3 years ago)
- Last Synced: 2025-02-10T15:33:11.085Z (over 1 year ago)
- Topics: pool, task-runner, taskpool, worker-pool
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# taskgo
taskgo is a lightweight task pool in Go
## Install
`go get github.com/limpo1989/taskgo@latest`
## API Overview
```
type TaskExecutor[T any] interface {
Exec(task T)
Cancel(timeout time.Duration)
}
func NewTaskExecutor[T any](parent context.Context, concurrency int32, executor func(ctx context.Context, task T)) TaskExecutor[T]
func NewActionExecutor(parent context.Context, concurrency int32) TaskExecutor[func()]
```
## Example
```go
package main
import (
"context"
"sync"
"github.com/limpo1989/taskgo"
)
func fib(n int) int {
switch n {
case 0, 1:
return n
default:
return fib(n-1) + fib(n-2)
}
}
func main() {
ae := taskgo.NewActionExecutor(context.Background(), 16)
const M = 10000
const N = 20
wg := &sync.WaitGroup{}
wg.Add(M)
for j := 0; j < M; j++ {
ae.Exec(func() {
fib(N)
wg.Done()
})
}
wg.Wait()
}
```