@@ -13,6 +13,16 @@ type Signaler interface {
13
13
Failed ()
14
14
}
15
15
16
+ // ChanSignal will send outputer signals on configurable channel.
17
+ type ChanSignal struct {
18
+ ch chan bool
19
+ }
20
+
21
+ // SyncSignal blocks waiting for a signal.
22
+ type SyncSignal struct {
23
+ ch chan bool
24
+ }
25
+
16
26
// SplitSignal guards one output signaler from multiple calls
17
27
// by using a simple reference counting scheme. If one Signaler consumer
18
28
// reports a Failed event, the Failed event will be send to the guarded Signaler
@@ -33,6 +43,29 @@ type CompositeSignal struct {
33
43
signalers []Signaler
34
44
}
35
45
46
+ // NewChanSignal create a new ChanSignal forwarding signals to a channel.
47
+ func NewChanSignal (ch chan bool ) * ChanSignal { return & ChanSignal {ch } }
48
+
49
+ // Completed sends true to the confiugred channel.
50
+ func (c * ChanSignal ) Completed () { c .ch <- true }
51
+
52
+ // Failed sends false to the confiugred channel.
53
+ func (c * ChanSignal ) Failed () { c .ch <- false }
54
+
55
+ // NewSyncSignal create a new SyncSignal signaler. Use Wait() method to wait for
56
+ // a signal from the publisher
57
+ func NewSyncSignal () * SyncSignal { return & SyncSignal {make (chan bool )} }
58
+
59
+ // Wait blocks waiting for a signal from the outputer. Wait return true if
60
+ // Completed was signaled and false if a Failed signal was received
61
+ func (s * SyncSignal ) Wait () bool { return <- s .ch }
62
+
63
+ // Completed sends true to the process waiting for a signal.
64
+ func (s * SyncSignal ) Completed () { s .ch <- true }
65
+
66
+ // Failed sends false to the process waiting for a signal.
67
+ func (s * SyncSignal ) Failed () { s .ch <- false }
68
+
36
69
// NewSplitSignaler creates a new SplitSignal if s is not nil.
37
70
// If s is nil, nil will be returned. The count is the number of events to be
38
71
// received before publishing the final event to the guarded Signaler.
0 commit comments