-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
42 lines (34 loc) · 878 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
41
42
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/codyoss/flo"
)
func main() {
// Create a cancelable context
ctx, cancel := context.WithCancel(context.Background())
// Giving the app a little time to process some data, then gracefully shutdown by canceling the context.
go func() {
time.Sleep(500 * time.Microsecond)
cancel()
}()
err := flo.NewBuilder(). // Create a flo builder
Add(helloWorld). // Add a Step
Add(exclaim). // Add another
BuildAndExecute(ctx) // BuildAndExecute processing(this blocks if there is no error)
// Checking for validation errors
if err != nil {
log.Fatal(err)
}
// Output:
// Hello World! (A bunch of times)
}
func helloWorld(ctx context.Context) (string, error) {
return "Hello World", nil
}
func exclaim(ctx context.Context, s string) error {
fmt.Printf("%s!\n", s)
return nil
}