-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.go
More file actions
66 lines (58 loc) · 1.32 KB
/
test.go
File metadata and controls
66 lines (58 loc) · 1.32 KB
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
60
61
62
63
64
65
66
package main
import (
"fmt"
"time"
"sync"
)
const NUM = 20
var waitChan sync.WaitGroup
func main() {
pipeMana := NewPipes()
pipe1 := PipeNode {
Name: "pipe1",
DataHander: pipeHandFn,
}
pipe2 := PipeNode{
Name: "pipe2",
PreNode: "pipe1",
DataHander: pipeHandFn,
}
pipe3 := PipeNode{
Name: "pipe3",
PreNode: "pipe2",
DataHander: pipeHandFn3,
}
pipeMana.SetNode(&pipe1, &pipe2, &pipe3)
//pipeMana.SetSemaphoreLength(20)
//test time Calculation
fmt.Println("Job Starting ..@time:", time.Now().Unix())
for i := 0; i < NUM; i++ {
waitChan.Add(1)
func (n int){
pipeMana.StartReceiveData("pipe1", n)
}(i)
}
waitChan.Wait()
fmt.Println("Job Finished ..@time:", time.Now().Unix())
}
func pipeHandFn(pipeData *PipeData) (status int8) {
data := pipeData.Data
switch v := data.(type) {
case int:
pipeData.Data = v + 1
//fmt.Println("After hander the Data:", pipeData)
return PIPE_NODE_STATUS_CONTINUE
}
}
func pipeHandFn3(pipeData *PipeData) (status int8) {
data := pipeData.Data
switch v := data.(type) {
case int:
pipeData.Data = v + 1
time.Sleep(time.Duration(2) * time.Second)
// if line 32 SetSemaphoreLength(1), you will see the total time will be 2*NUM seconds;
//fmt.Println("After Last hander the Data:", pipeData.Data)
waitChan.Done()
return PIPE_NODE_STATUS_CONTINUE
}
}