Skip to content

Commit 0681fed

Browse files
authored
Merge pull request #6 from arduino/scerza/sync-chan-remove
Remove `syncChannel` and push messages directly to output
2 parents 5c0e058 + 1c7a2c2 commit 0681fed

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

discovery_server.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ type DiscoveryServer struct {
9191
initialized bool
9292
started bool
9393
syncStarted bool
94-
syncChannel chan *message
9594
cachedPorts map[string]*Port
9695
cachedErr string
9796
}
@@ -246,22 +245,12 @@ func (d *DiscoveryServer) startSync() {
246245
d.outputChan <- messageError("start_sync", "Discovery already STARTed, cannot START_SYNC")
247246
return
248247
}
249-
c := make(chan *message, 10) // buffer up to 10 events
250-
d.syncChannel = c
251248
if err := d.impl.StartSync(d.syncEvent, d.errorEvent); err != nil {
252249
d.outputChan <- messageError("start_sync", "Cannot START_SYNC: "+err.Error())
253-
close(d.syncChannel) // do not leak channel...
254-
d.syncChannel = nil
255250
return
256251
}
257252
d.syncStarted = true
258253
d.outputChan <- messageOk("start_sync")
259-
260-
go func() {
261-
for e := range c {
262-
d.outputChan <- e
263-
}
264-
}()
265254
}
266255

267256
func (d *DiscoveryServer) stop() {
@@ -275,22 +264,20 @@ func (d *DiscoveryServer) stop() {
275264
}
276265
d.started = false
277266
if d.syncStarted {
278-
close(d.syncChannel)
279-
d.syncChannel = nil
280267
d.syncStarted = false
281268
}
282269
d.outputChan <- messageOk("stop")
283270
}
284271

285272
func (d *DiscoveryServer) syncEvent(event string, port *Port) {
286-
d.syncChannel <- &message{
273+
d.outputChan <- &message{
287274
EventType: event,
288275
Port: port,
289276
}
290277
}
291278

292279
func (d *DiscoveryServer) errorEvent(msg string) {
293-
d.syncChannel <- messageError("start_sync", msg)
280+
d.outputChan <- messageError("start_sync", msg)
294281
}
295282

296283
func (d *DiscoveryServer) outputProcessor(outWriter io.Writer) {

0 commit comments

Comments
 (0)