An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# worker

Package worker implements an easy to use concurrency framework for
multiple-job Go program.

[![GoDoc](https://godoc.org/github.com/duzy/worker?status.svg)](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() {
// ...
}
}
```