https://github.com/bsm/workhorse
A simple worker abstraction on top of sync/errgroup with custom middlewares.
https://github.com/bsm/workhorse
Last synced: 8 months ago
JSON representation
A simple worker abstraction on top of sync/errgroup with custom middlewares.
- Host: GitHub
- URL: https://github.com/bsm/workhorse
- Owner: bsm
- License: other
- Created: 2020-03-27T09:33:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-27T11:26:45.000Z (about 6 years ago)
- Last Synced: 2025-06-13T19:04:14.598Z (12 months ago)
- Language: Go
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Workhorse
[](https://travis-ci.org/bsm/workhorse)
[](http://godoc.org/github.com/bsm/workhorse)
[](https://opensource.org/licenses/Apache-2.0)
A simple worker abstraction on top of [errgroup](https://pkg.go.dev/golang.org/x/sync/errgroup) with custom middlewares.
## Examples
```go
import (
"context"
"fmt"
"sync/atomic"
"github.com/bsm/workhorse"
)
func main() {
// define root context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var count uint32
// init a worker
w := workhorse.New(ctx)
// schedule task "one"
w.Go("one", func(_ context.Context) error {
for i := 0; i < 1000; i++ {
atomic.AddUint32(&count, 1)
}
return nil
})
// schedule task "two"
w.Go("two", func(_ context.Context) error {
for i := 0; i < 1000; i++ {
atomic.AddUint32(&count, 2)
}
return nil
})
// wait for both tasks to complete
if err := w.Wait(); err != nil {
panic(err)
}
fmt.Println(count)
// Output:
// 3000}
```
## Documentation
Full documentation is available on [GoDoc](https://pkg.go.dev/github.com/bsm/workhorse)