-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
42 lines (35 loc) · 835 Bytes
/
example_test.go
File metadata and controls
42 lines (35 loc) · 835 Bytes
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 weave_test
import (
"context"
"fmt"
"github.com/bpradana/weave"
)
func ExampleGraph_Run() {
graph := weave.NewGraph()
fetchName, err := weave.AddTask(graph, "fetch-name", func(ctx context.Context, deps weave.DependencyResolver) (string, error) {
return "Ada", nil
})
if err != nil {
panic(err)
}
greet, err := weave.AddTask(graph, "greet", func(ctx context.Context, deps weave.DependencyResolver) (string, error) {
name, err := fetchName.Value(deps)
if err != nil {
return "", err
}
return fmt.Sprintf("Hello, %s!", name), nil
}, weave.DependsOn(fetchName))
if err != nil {
panic(err)
}
results, _, err := graph.Run(context.Background())
if err != nil {
panic(err)
}
message, err := greet.Value(results)
if err != nil {
panic(err)
}
fmt.Println(message)
// Output: Hello, Ada!
}