File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ type DiscoveryServer struct {
94
94
initialized bool
95
95
started bool
96
96
syncStarted bool
97
+ syncChannel chan interface {}
97
98
}
98
99
99
100
// NewDiscoveryServer creates a new discovery server backed by the
@@ -228,12 +229,22 @@ func (d *DiscoveryServer) startSync() {
228
229
d .outputError ("start_sync" , "Discovery already STARTed, cannot START_SYNC" )
229
230
return
230
231
}
232
+ d .syncChannel = make (chan interface {}, 10 ) // buffer up to 10 events
231
233
if err := d .impl .StartSync (d .syncEvent ); err != nil {
232
234
d .outputError ("start_sync" , "Cannot START_SYNC: " + err .Error ())
235
+ close (d .syncChannel ) // do not leak channel...
236
+ d .syncChannel = nil
233
237
return
234
238
}
235
239
d .syncStarted = true
236
240
d .outputOk ("start_sync" )
241
+ go d .consumeEvents (d .syncChannel )
242
+ }
243
+
244
+ func (d * DiscoveryServer ) consumeEvents (c <- chan interface {}) {
245
+ for e := range c {
246
+ d .output (e )
247
+ }
237
248
}
238
249
239
250
func (d * DiscoveryServer ) stop () {
@@ -246,7 +257,11 @@ func (d *DiscoveryServer) stop() {
246
257
return
247
258
}
248
259
d .started = false
249
- d .syncStarted = false
260
+ if d .syncStarted {
261
+ close (d .syncChannel )
262
+ d .syncChannel = nil
263
+ d .syncStarted = false
264
+ }
250
265
d .outputOk ("stop" )
251
266
}
252
267
@@ -255,10 +270,10 @@ func (d *DiscoveryServer) syncEvent(event string, port *Port) {
255
270
EventType string `json:"eventType"`
256
271
Port * Port `json:"port"`
257
272
}
258
- d .output ( & syncOutputJSON {
273
+ d .syncChannel <- & syncOutputJSON {
259
274
EventType : event ,
260
275
Port : port ,
261
- })
276
+ }
262
277
}
263
278
264
279
type genericMessageJSON struct {
You can’t perform that action at this time.
0 commit comments