-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (65 loc) · 1.35 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"github.com/discretemind/glink"
"github.com/discretemind/glink/stream"
"time"
)
type packet struct {
Type string
Num int
}
func input(done chan bool) func(input stream.IInputStream) {
return func(input stream.IInputStream) {
go func() {
i := 0
for i < 10 {
fmt.Println("Task ", i)
if i%2 == 0 {
input.Push(packet{
Type: "type X",
Num: i,
})
} else {
input.Push(packet{
Type: "type Y",
Num: i,
})
}
time.Sleep(1 * time.Second)
i++
}
close(done)
}()
}
}
func main() {
fmt.Println("Start")
done := make(chan bool, 1)
job := glink.Standalone()
inputSet := job.Task("simple", input(done), func(i interface{}) time.Time {
return time.Now()
})
set2 := inputSet.Map(func(value interface{}) (interface{}, error) {
p := value.(packet)
p.Num *= 2
return p, nil
}).Name("All items")
set2.Print()
set3 := set2.FilterByField("Type", "type X").Map(func(value interface{}) (interface{}, error) {
p := value.(packet)
p.Num *= 2
return p, nil
}).Name("Filtered X")
set3.Print()
set3.Filter(func(value interface{}) bool {
return value.(packet).Type == "type Y"
}).Map(func(value interface{}) (interface{}, error) {
p := value.(packet)
p.Num *= 10
return p, nil
}).Name("Filtered Y").Print()
go job.Run()
fmt.Println("Wait")
<-done
}