Skip to content

Remove syncChannel and push messages directly to output #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions discovery_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ type DiscoveryServer struct {
initialized bool
started bool
syncStarted bool
syncChannel chan *message
cachedPorts map[string]*Port
cachedErr string
}
Expand Down Expand Up @@ -246,22 +245,12 @@ func (d *DiscoveryServer) startSync() {
d.outputChan <- messageError("start_sync", "Discovery already STARTed, cannot START_SYNC")
return
}
c := make(chan *message, 10) // buffer up to 10 events
d.syncChannel = c
if err := d.impl.StartSync(d.syncEvent, d.errorEvent); err != nil {
d.outputChan <- messageError("start_sync", "Cannot START_SYNC: "+err.Error())
close(d.syncChannel) // do not leak channel...
d.syncChannel = nil
return
}
d.syncStarted = true
d.outputChan <- messageOk("start_sync")

go func() {
for e := range c {
d.outputChan <- e
}
}()
}

func (d *DiscoveryServer) stop() {
Expand All @@ -275,22 +264,20 @@ func (d *DiscoveryServer) stop() {
}
d.started = false
if d.syncStarted {
close(d.syncChannel)
d.syncChannel = nil
d.syncStarted = false
}
d.outputChan <- messageOk("stop")
}

func (d *DiscoveryServer) syncEvent(event string, port *Port) {
d.syncChannel <- &message{
d.outputChan <- &message{
EventType: event,
Port: port,
}
}

func (d *DiscoveryServer) errorEvent(msg string) {
d.syncChannel <- messageError("start_sync", msg)
d.outputChan <- messageError("start_sync", msg)
}

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