https://github.com/duzy/worker
Easier Go Concurrency Framework
https://github.com/duzy/worker
concurrency-framework golang
Last synced: 5 months ago
JSON representation
Easier Go Concurrency Framework
- Host: GitHub
- URL: https://github.com/duzy/worker
- Owner: duzy
- License: bsd-3-clause
- Created: 2016-03-21T08:33:08.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-06-09T07:36:50.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T17:35:25.755Z (almost 2 years ago)
- Topics: concurrency-framework, golang
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# worker
Package worker implements an easy to use concurrency framework for
multiple-job Go program.
[](http://godoc.org/github.com/duzy/worker)
Here is a quick example demonstrating the usage.
```go
package example
import "github.com/duzy/worker"
type StepOne struct {
Param string
}
func (job *StepOne) Go() worker.Result {
// do job for step one
return &StepTwo{}
}
type StepTwo struct {
}
func (job *StepTwo) Go() worker.Result {
// do job for step two
return &StepThree{}
}
type StepThree struct {
}
func (job *StepThree) Go() worker.Result {
// do job for step three
return nil
}
const NumberOfConcurrency = 10
func main() {
w := worker.SpawnN(NumberOfConcurrency)
w.Do(&StepOne{ "anything goes" })
w.Do(&StepOne{ "anything goes" })
w.Do(&StepOne{ "anything goes" })
w.Do(&StepOne{ "anything goes" })
w.Kill()
w = worker.SpawnN(3)
sentry := w.Sentry()
sentry.Guard(&StepOne{ "anything goes" })
sentry.Guard(&StepOne{ "anything goes" })
sentry.Guard(&StepOne{ "anything goes" })
for result, _ := range sentry.Wait() {
// ...
}
}
```