https://github.com/daniilty/pipeline
Go async pipeline library
https://github.com/daniilty/pipeline
async go golang pipeline
Last synced: over 1 year ago
JSON representation
Go async pipeline library
- Host: GitHub
- URL: https://github.com/daniilty/pipeline
- Owner: daniilty
- Created: 2023-12-11T19:09:19.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-11T19:21:14.000Z (over 2 years ago)
- Last Synced: 2025-01-26T01:20:29.001Z (over 1 year ago)
- Topics: async, go, golang, pipeline
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Pipelines
### Goal
This package provides you with a simple way to process business pipelines in async way.
The idea is you don't have to wait for some function to finish, instead you wait for data this function provides, everything else can be async.
### Installation
```bash
$ go get github.com/daniilty/pipeline@latest
```
### Usage
```go
// set timeout to 1 second(after timeout all waiting runners will get timeout error)
// set to 0 to disable
pipe := pipeline.NewPipeline(1 * time.Second)
pipe.Execute(context.Background(),
func(_ context.Context, provider pipeline.Provider) {
provider.ProvideData("d1", "somedata", nil)
},
func(_ context.Context, provider pipeline.Provider) {
wd1, ok := provider.WaitData("d1")
if !ok {
log.Fatal("did not get d1")
}
if wd1.Err() != nil {
log.Fatal("d1 fail")
}
provider.ProvideData("d2", nil, errors.New("shit happened"))
},
func(_ context.Context, provider pipeline.Provider) {
wd2, ok := provider.WaitData("d2")
if !ok {
log.Fatal("did not get d2")
}
if wd2.Err() != nil {
log.Fatalf("d2 fail: %s", wd.Err().Error())
}
},
)
```