-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular.go
More file actions
28 lines (25 loc) · 955 Bytes
/
circular.go
File metadata and controls
28 lines (25 loc) · 955 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
package nodegraphflow
import "time"
// CircularNodePolicy enforces a shutdown procedure for the chain iteration
type CircularNodePolicy struct {
Timeout time.Duration
RequiredForSuccess bool
RestartOnError bool
IsCircularNode bool
StopChain *chan int
}
// BuildChain will bind nodes into a chain which just means that the last node will have the first node as a sibling.
// Does not bind any siblings and no siblings should be set manually.
// The usecase for this would be running an refresh loop that has a lifetime which usually would equal that of the program.
func BuildChain[T interface{}](stopChain *chan int, nodes ...*Node[T]) {
for k := range nodes {
if len(nodes)-1 != k {
nodes[k].SubNodes = []*Node[T]{nodes[k+1]}
}
if len(nodes)-1 == k {
nodes[k].SubNodes = []*Node[T]{nodes[0]}
}
nodes[k].CircularNodePolicy.IsCircularNode = true
nodes[k].CircularNodePolicy.StopChain = stopChain
}
}