-
Notifications
You must be signed in to change notification settings - Fork 6
/
example_test.go
41 lines (34 loc) · 898 Bytes
/
example_test.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
package dag_test
import (
"errors"
"fmt"
"github.com/natessilva/dag"
)
func ExampleRunner() {
var r dag.Runner
r.AddVertex("one", func() error {
fmt.Println("one and two will run in parallel before three")
return nil
})
r.AddVertex("two", func() error {
fmt.Println("one and two will run in parallel before three")
return nil
})
r.AddVertex("three", func() error {
fmt.Println("three will run before four")
return errors.New("three is broken")
})
r.AddVertex("four", func() error {
fmt.Println("four will never run")
return nil
})
r.AddEdge("one", "three")
r.AddEdge("two", "three")
r.AddEdge("three", "four")
fmt.Printf("the runner terminated with: %v\n", r.Run())
// Output:
// one and two will run in parallel before three
// one and two will run in parallel before three
// three will run before four
// the runner terminated with: three is broken
}