Skip to content

Commit 48b60e6

Browse files
committed
We do not need the closing channel exposed, Stop() is sufficient
1 parent 090c9aa commit 48b60e6

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

discovery_server.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Discovery interface {
6666
// StartSync is called to put the discovery in event mode. When the
6767
// function returns the discovery must send port events ("add" or "remove")
6868
// using the eventCB function.
69-
StartSync(eventCB EventCallback) (chan<- bool, error)
69+
StartSync(eventCB EventCallback) error
7070

7171
// Stop stops the discovery internal subroutines. If the discovery is
7272
// in event mode it must stop sending events through the eventCB previously
@@ -90,7 +90,6 @@ type DiscoveryServer struct {
9090
initialized bool
9191
started bool
9292
syncStarted bool
93-
syncCloseChan chan<- bool
9493
}
9594

9695
// NewDiscoveryServer creates a new discovery server backed by the
@@ -224,14 +223,12 @@ func (d *DiscoveryServer) startSync() {
224223
d.outputError("start_sync", "Discovery already STARTed, cannot START_SYNC")
225224
return
226225
}
227-
if c, err := d.impl.StartSync(d.syncEvent); err != nil {
226+
if err := d.impl.StartSync(d.syncEvent); err != nil {
228227
d.outputError("start_sync", "Cannot START_SYNC: "+err.Error())
229228
return
230-
} else {
231-
d.syncCloseChan = c
232-
d.syncStarted = true
233-
d.outputOk("start_sync")
234229
}
230+
d.syncStarted = true
231+
d.outputOk("start_sync")
235232
}
236233

237234
func (d *DiscoveryServer) stop() {
@@ -243,14 +240,8 @@ func (d *DiscoveryServer) stop() {
243240
d.outputError("stop", "Cannot STOP: "+err.Error())
244241
return
245242
}
246-
if d.started {
247-
d.started = false
248-
}
249-
if d.syncStarted {
250-
d.syncCloseChan <- true
251-
close(d.syncCloseChan)
252-
d.syncStarted = false
253-
}
243+
d.started = false
244+
d.syncStarted = false
254245
d.outputOk("stop")
255246
}
256247

dummy-discovery/main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
type DummyDiscovery struct {
3232
startSyncCount int
3333
listCount int
34+
closeChan chan<- bool
3435
}
3536

3637
func main() {
@@ -61,16 +62,21 @@ func (d *DummyDiscovery) Start() error {
6162
}
6263

6364
func (d *DummyDiscovery) Stop() error {
65+
if d.closeChan != nil {
66+
d.closeChan <- true
67+
d.closeChan = nil
68+
}
6469
return nil
6570
}
6671

67-
func (d *DummyDiscovery) StartSync(eventCB discovery.EventCallback) (chan<- bool, error) {
72+
func (d *DummyDiscovery) StartSync(eventCB discovery.EventCallback) error {
6873
d.startSyncCount++
6974
if d.startSyncCount%5 == 0 {
70-
return nil, errors.New("could not start_sync every 5 times")
75+
return errors.New("could not start_sync every 5 times")
7176
}
7277

7378
c := make(chan bool)
79+
d.closeChan = c
7480

7581
// Run synchronous event emitter
7682
go func() {
@@ -113,7 +119,7 @@ func (d *DummyDiscovery) StartSync(eventCB discovery.EventCallback) (chan<- bool
113119
}
114120
}()
115121

116-
return c, nil
122+
return nil
117123
}
118124

119125
var dummyCounter = 0

0 commit comments

Comments
 (0)