-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecv2src.go
51 lines (44 loc) · 836 Bytes
/
recv2src.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
package watched
type branch struct {
EventSrc
j chan JounalEvent
s chan StatusEvent
}
type RecvToSrc struct {
out []branch
}
type BranchConfig struct {
JournalQLen int
StatusQLen int
}
func (rs *RecvToSrc) Branch(cfg BranchConfig) EventSrc {
i := len(rs.out)
rs.out = append(rs.out, branch{
j: make(chan JounalEvent, cfg.JournalQLen),
s: make(chan StatusEvent, cfg.StatusQLen),
})
res := &rs.out[i]
res.Journal = res.j
res.Status = res.s
return res.EventSrc
}
func (rs *RecvToSrc) OnJournalEvent(e JounalEvent) error {
for _, b := range rs.out {
b.j <- e
}
return nil
}
func (rs *RecvToSrc) OnStatusEvent(e StatusEvent) error {
for _, b := range rs.out {
b.s <- e
}
return nil
}
func (rs *RecvToSrc) Close() error {
for _, b := range rs.out {
close(b.j)
close(b.s)
}
rs.out = nil
return nil
}