@@ -390,44 +390,38 @@ func (disc *PluggableDiscovery) List() ([]*Port, error) {
390390 }
391391}
392392
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-
409393// StartSync puts the discovery in "events" mode: the discovery will send "add"
410394// and "remove" events each time a new port is detected or removed respectively.
411395// After calling StartSync an initial burst of "add" events may be generated to
412396// 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 ) {
414401 if err := disc .sendCommand ("START_SYNC\n " ); err != nil {
415- return err
402+ return nil , err
416403 }
417404
418405 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 )
420407 } 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 )
422409 } 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 )
424411 }
425412
426413 disc .statusMutex .Lock ()
427414 defer disc .statusMutex .Unlock ()
428415 disc .state = Syncing
429416 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
431425}
432426
433427// ListSync returns a list of the available ports. The list is a cache of all the
0 commit comments