Skip to content

Commit b3a0ccd

Browse files
committed
Fix pluggable discoveries parallelization
1 parent ad47218 commit b3a0ccd

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

arduino/discovery/discoverymanager/discoverymanager.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package discoverymanager
1717

1818
import (
19-
"context"
2019
"fmt"
2120
"sync"
2221

@@ -72,7 +71,6 @@ func (dm *DiscoveryManager) Add(disc *discovery.PluggableDiscovery) error {
7271
// Returns a list of errors returned by each call of f.
7372
func (dm *DiscoveryManager) parallelize(f func(d *discovery.PluggableDiscovery) error) []error {
7473
var wg sync.WaitGroup
75-
ctx, cancel := context.WithCancel(context.Background())
7674
errChan := make(chan error)
7775
for _, d := range dm.discoveries {
7876
wg.Add(1)
@@ -85,23 +83,16 @@ func (dm *DiscoveryManager) parallelize(f func(d *discovery.PluggableDiscovery)
8583
}
8684

8785
// Wait in a goroutine to collect eventual errors running a discovery.
88-
// When all goroutines that are calling discoveries are done call cancel
89-
// to avoid blocking if there are no errors.
86+
// When all goroutines that are calling discoveries are done close the errors chan.
9087
go func() {
9188
wg.Wait()
92-
cancel()
89+
close(errChan)
9390
}()
9491

9592
errs := []error{}
96-
for {
97-
select {
98-
case <-ctx.Done():
99-
goto done
100-
case err := <-errChan:
101-
errs = append(errs, err)
102-
}
93+
for err := range errChan {
94+
errs = append(errs, err)
10395
}
104-
done:
10596
return errs
10697
}
10798

0 commit comments

Comments
 (0)