File tree Expand file tree Collapse file tree 1 file changed +4
-13
lines changed
arduino/discovery/discoverymanager Expand file tree Collapse file tree 1 file changed +4
-13
lines changed Original file line number Diff line number Diff line change 1616package discoverymanager
1717
1818import (
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.
7372func (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
You can’t perform that action at this time.
0 commit comments