8000 export default signalers · packplusplus/libbeat@6524b53 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit 6524b53

Browse files
author
urso
committed
export default signalers
1 parent 4ef2892 commit 6524b53

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

outputs/signal.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ type Signaler interface {
1313
Failed()
1414
}
1515

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+
1626
// SplitSignal guards one output signaler from multiple calls
1727
// by using a simple reference counting scheme. If one Signaler consumer
1828
// reports a Failed event, the Failed event will be send to the guarded Signaler
@@ -33,6 +43,29 @@ type CompositeSignal struct {
3343
signalers []Signaler
3444
}
3545

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+
3669
// NewSplitSignaler creates a new SplitSignal if s is not nil.
3770
// If s is nil, nil will be returned. The count is the number of events to be
3871
// received before publishing the final event to the guarded Signaler.

publisher/sync.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ type syncPublisher struct {
1212

1313
type syncClient func(message)
1414

15-
type syncSignal struct {
16-
ch chan bool
17-
}
18-
1915
func newSyncPublisher(pub *PublisherType) *syncPublisher {
2016
s := &syncPublisher{pub: pub}
2117
s.messageWorker.init(&pub.wsPublisher, 1000, newPreprocessor(pub, s))
@@ -45,13 +41,8 @@ func (c syncClient) PublishEvents(events []common.MapStr) bool {
4541
}
4642

4743
func (c syncClient) send(m message) bool {
48-
sync := newSyncSignal()
44+
sync := outputs.NewSyncSignal()
4945
m.signal = sync
5046
c(m)
51-
return sync.wait()
47+
return sync.Wait()
5248
}
53-
54-
func newSyncSignal() *syncSignal { return &syncSignal{make(chan bool)} }
55-
func (s *syncSignal) wait() bool { return <-s.ch }
56-
func (s *syncSignal) Completed() { s.ch <- true }
57-
func (s *syncSignal) Failed() { s.ch <- false }

0 commit comments

Comments
 (0)
0