-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
40 lines (34 loc) · 956 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"context"
"fmt"
"github.com/codyoss/flo"
)
func main() {
// make an input channel to feed the pipeline some data
inputChannel := make(chan string, 2)
// put some data on the channel
inputChannel <- "Hello World"
inputChannel <- "Another message"
// Closing the channel will trigger the pipeline to shutdown. Regularly you would be keep putting data on the
// channel and close in another goroutine(and not before the pipline was created), but we are trying to keep things
// simple here.
close(inputChannel)
// Register the input channel
flo.NewBuilder(flo.WithInput(inputChannel)).
Add(exclaim).
Add(exclaim).
Add(exclaim).
Add(print).
BuildAndExecute(context.Background())
// Output:
// Hello World!!!
// Another message!!!
}
func exclaim(ctx context.Context, msg string) (string, error) {
return msg + "!", nil
}
func print(ctx context.Context, msg string) error {
fmt.Println(msg)
return nil
}