/
main.go
59 lines (44 loc) · 1.04 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* ######################################################################
# Author: (zfly1207@126.com)
# Created Time: 2020-06-13 19:55:13
# File Name: main.go
# Description:
####################################################################### */
package main
import (
"fmt"
"time"
"github.com/ant-libs-go/flow"
)
type TestAPloy struct {
flow.Ploy
}
func (TestAPloy) Run(c flow.FlowContext) {
ctx := c.(*PContext)
ctx.Count++
time.Sleep(time.Second)
fmt.Printf("%s: test-a\n", time.Now().Format("2006-01-02 15:04:05"))
}
type TestBPloy struct {
flow.Ploy
}
func (TestBPloy) Run(c flow.FlowContext) {
ctx := c.(*PContext)
ctx.Count++
time.Sleep(time.Second)
fmt.Printf("%s: test-b\n", time.Now().Format("2006-01-02 15:04:05"))
}
type PContext struct {
flow.CoreContext
Count int
}
func main() {
mainFlow := flow.New()
mainFlow.AddPloy(&TestAPloy{}, &TestBPloy{})
subFlow := flow.NewPipeFlow()
subFlow.AddPloy(&TestAPloy{}, &TestBPloy{})
mainFlow.AddFlow(subFlow)
ctx := &PContext{}
mainFlow.Run(ctx)
fmt.Println(ctx.Count)
}