@@ -390,44 +390,38 @@ func (disc *PluggableDiscovery) List() ([]*Port, error) {
390
390
}
391
391
}
392
392
393
- // EventChannel creates a channel used to receive events from the pluggable discovery.
394
- // The event channel must be consumed as quickly as possible since it may block the
395
- // discovery if it becomes full. The channel size is configurable.
396
- func (disc * PluggableDiscovery ) EventChannel (size int ) <- chan * Event {
397
- disc .statusMutex .Lock ()
398
- defer disc .statusMutex .Unlock ()
399
- if disc .eventChan != nil {
400
- // In case there is already an existing event channel in use we close it
401
- // before creating a new one.
402
- close (disc .eventChan )
403
- }
404
- c := make (chan * Event , size )
405
- disc .eventChan = c
406
- return c
407
- }
408
-
409
393
// StartSync puts the discovery in "events" mode: the discovery will send "add"
410
394
// and "remove" events each time a new port is detected or removed respectively.
411
395
// After calling StartSync an initial burst of "add" events may be generated to
412
396
// report all the ports available at the moment of the start.
413
- func (disc * PluggableDiscovery ) StartSync () error {
397
+ // It also creates a channel used to receive events from the pluggable discovery.
398
+ // The event channel must be consumed as quickly as possible since it may block the
399
+ // discovery if it becomes full. The channel size is configurable.
400
+ func (disc * PluggableDiscovery ) StartSync (size int ) (<- chan * Event , error ) {
414
401
if err := disc .sendCommand ("START_SYNC\n " ); err != nil {
415
- return err
402
+ return nil , err
416
403
}
417
404
418
405
if msg , err := disc .waitMessage (time .Second * 10 ); err != nil {
419
- return fmt .Errorf ("calling START_SYNC: %w" , err )
406
+ return nil , fmt .Errorf ("calling START_SYNC: %w" , err )
420
407
} else if msg .EventType != "start_sync" {
421
- return errors .Errorf (tr ("communication out of sync, expected 'start_sync', received '%s'" ), msg .EventType )
408
+ return nil , errors .Errorf (tr ("communication out of sync, expected 'start_sync', received '%s'" ), msg .EventType )
422
409
} else if msg .Message != "OK" || msg .Error {
423
- return errors .Errorf (tr ("command failed: %s" ), msg .Message )
410
+ return nil , errors .Errorf (tr ("command failed: %s" ), msg .Message )
424
411
}
425
412
426
413
disc .statusMutex .Lock ()
427
414
defer disc .statusMutex .Unlock ()
428
415
disc .state = Syncing
429
416
disc .cachedPorts = map [string ]* Port {}
430
- return nil
417
+ if disc .eventChan != nil {
418
+ // In case there is already an existing event channel in use we close it
419
+ // before creating a new one.
420
+ close (disc .eventChan )
421
+ }
422
+ c := make (chan * Event , size )
423
+ disc .eventChan = c
424
+ return c , nil
431
425
}
432
426
433
427
// ListSync returns a list of the available ports. The list is a cache of all the
0 commit comments