-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_cluster_test.go
58 lines (55 loc) · 1.15 KB
/
example_cluster_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package nject_test
import (
"fmt"
"github.com/muir/nject"
)
func ExampleCluster() {
chain := nject.Sequence("overall",
func() string {
return "example string"
},
nject.Cluster("first-cluster",
func(s string) int32 {
return int32(len(s))
},
func() int64 {
fmt.Println("included even though no consumer")
return 0
},
func(i int32) {
fmt.Println("auto-desired in 1st cluster")
},
func(i int32) int64 {
return int64(i)
},
),
nject.Cluster("second-cluster",
func(s string) uint32 {
return uint32(len(s))
},
func(i uint32) {
fmt.Println("auto-desired in 2nd cluster")
},
func(i int64, u uint32) uint64 {
return uint64(uint32(i) + u)
},
),
)
_ = nject.Run("does not consume uint64",
chain,
func(s string) {
fmt.Println("no need for data from clusters")
},
)
_ = nject.Run("consumes uint64",
chain,
func(u uint64) {
fmt.Println("got value that needed both chains -", u)
},
)
// Output: no need for data from clusters
// included even though no consumer
// auto-desired in 1st cluster
// auto-desired in 2nd cluster
// got value that needed both chains - 28
}