https://github.com/kamildrazkiewicz/go-flow
Simply way to control goroutines execution order based on dependencies
https://github.com/kamildrazkiewicz/go-flow
concurency go goflow golang goroutine goroutine-order
Last synced: 9 months ago
JSON representation
Simply way to control goroutines execution order based on dependencies
- Host: GitHub
- URL: https://github.com/kamildrazkiewicz/go-flow
- Owner: kamildrazkiewicz
- License: mit
- Created: 2016-09-25T14:46:09.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-14T12:10:41.000Z (over 6 years ago)
- Last Synced: 2024-10-25T05:22:37.371Z (about 1 year ago)
- Topics: concurency, go, goflow, golang, goroutine, goroutine-order
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 220
- Watchers: 11
- Forks: 29
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go-cn - go-flow
- awesome-go - go-flow - | - | - | (Goroutines / Advanced Console UIs)
- awesome-go - go-flow - Control goroutines execution order. (Goroutines / Search and Analytic Databases)
- awesome-go-plus - go-flow - Control goroutines execution order.  (Goroutines / Search and Analytic Databases)
- awesome-go - go-flow - Control goroutines execution order. (Goroutines / Search and Analytic Databases)
- awesome-go-cn - go-flow - flow) [![godoc][D]](https://godoc.org/github.com/kamildrazkiewicz/go-flow) (Goroutines / 检索及分析资料库)
- awesome-go - go-flow - Control goroutines execution order. (Goroutines / Search and Analytic Databases)
- awesome-go-extra - go-flow - 09-25T14:46:09Z|2019-05-14T12:10:41Z| (Goroutines / Advanced Console UIs)
- awesome-go - go-flow - 控制协程执行顺序。 (<span id="协程-Coroutines">协程 Coroutines</span> / <span id="高级控制台用户界面-advanced-console-uis">高级控制台用户界面 Advanced Console UIs</span>)
- awesome-go - go-flow - Control goroutines execution order. - :arrow_down:1 - :star:2 (Goroutines / Advanced Console UIs)
- awesome-go - go-flow - Simply way to control goroutines execution order based on dependencies - ★ 86 (Goroutines)
- awesome-go - go-flow - Control goroutines execution order. (Goroutines / Search and Analytic Databases)
- awesome-go-with-stars - go-flow - Control goroutines execution order. (Goroutines / Search and Analytic Databases)
- awesome-go - go-flow - Control goroutines execution order. (Goroutines / Search and Analytic Databases)
- fucking-awesome-go - go-flow - Control goroutines execution order. (Goroutines / Search and Analytic Databases)
- awesome-Char - go-flow - Control goroutines execution order. (Goroutines / Advanced Console UIs)
- awesome-go-cn - go-flow - flow) [![godoc][D]](https://godoc.org/github.com/kamildrazkiewicz/go-flow) (Goroutines / 检索及分析资料库)
- awesome-go - go-flow - Control goroutines execution order. (Goroutines / Advanced Console UIs)
- awesome-go-cn - go-flow
- awesome-go - go-flow - Control goroutines execution order. (Goroutines / Advanced Console UIs)
README
# Goflow
[](http://godoc.org/github.com/kamildrazkiewicz/go-flow) [](https://raw.githubusercontent.com/kamildrazkiewicz/go-flow/master/LICENSE) [](http://godoc.org/github.com/kamildrazkiewicz/go-flow) [](https://goreportcard.com/report/github.com/kamildrazkiewicz/go-flow) [](https://travis-ci.org/kamildrazkiewicz/go-flow) [](https://coveralls.io/github/kamildrazkiewicz/go-flow?branch=master)
Goflow is a simply package to control goroutines execution order based on dependencies. It works similar to ```async.auto``` from [node.js async package](https://github.com/caolan/async), but for Go.

## Install
Install the package with:
```bash
go get github.com/kamildrazkiewicz/go-flow
```
Import it with:
```go
import "github.com/kamildrazkiewicz/go-flow"
```
and use `goflow` as the package name inside the code.
## Example
```go
package main
import (
"fmt"
"github.com/kamildrazkiewicz/go-flow"
"time"
)
func main() {
f1 := func(r map[string]interface{}) (interface{}, error) {
fmt.Println("function1 started")
time.Sleep(time.Millisecond * 1000)
return 1, nil
}
f2 := func(r map[string]interface{}) (interface{}, error) {
time.Sleep(time.Millisecond * 1000)
fmt.Println("function2 started", r["f1"])
return "some results", nil
}
f3 := func(r map[string]interface{}) (interface{}, error) {
fmt.Println("function3 started", r["f1"])
return nil, nil
}
f4 := func(r map[string]interface{}) (interface{}, error) {
fmt.Println("function4 started", r)
return nil, nil
}
res, err := goflow.New().
Add("f1", nil, f1).
Add("f2", []string{"f1"}, f2).
Add("f3", []string{"f1"}, f3).
Add("f4", []string{"f2", "f3"}, f4).
Do()
fmt.Println(res, err)
}
```
Output will be:
```
function1 started
function3 started 1
function2 started 1
function4 started map[f2:some results f3:]
map[f1:1 f2:some results f3: f4:]
```