Skip to content

Commit a8c5220

Browse files
silvanocerzacmaglie
authored andcommitted
Enhanced handling of some discoveries states
1 parent 73ba971 commit a8c5220

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

arduino/discovery/discoverymanager/discoverymanager.go

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func (dm *DiscoveryManager) Add(disc *discovery.PluggableDiscovery) error {
5858
// returns the first error it meets or nil
5959
func (dm *DiscoveryManager) RunAll() error {
6060
for _, d := range dm.discoveries {
61+
if d.IsAlive() {
62+
// This discovery is already running, nothing to do
63+
continue
64+
}
65+
6166
if err := d.Run(); err != nil {
6267
return err
6368
}
@@ -81,6 +86,11 @@ func (dm *DiscoveryManager) StartAll() error {
8186
func (dm *DiscoveryManager) StartSyncAll() (<-chan *discovery.Event, []error) {
8287
errs := []error{}
8388
for _, d := range dm.discoveries {
89+
if d.IsEventMode() {
90+
// Already started, nothing to do
91+
continue
92+
}
93+
8494
eventCh := d.EventChannel(5)
8595
if err := d.StartSync(); err != nil {
8696
errs = append(errs, err)

commands/board/list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,11 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
273273
Error: boardsError,
274274
}
275275
case <-interrupt:
276-
err := pm.DiscoveryManager().QuitAll()
276+
err := pm.DiscoveryManager().StopAll()
277277
if err != nil {
278278
outChan <- &rpc.BoardListWatchResponse{
279279
EventType: "error",
280-
Error: err.Error(),
280+
Error: fmt.Sprintf("stopping discoveries: %s", err),
281281
}
282282
// Don't close the channel if quitting all discoveries
283283
// failed, otherwise some processes might be left running.

0 commit comments

Comments
 (0)