File tree 1 file changed +4
-13
lines changed
arduino/discovery/discoverymanager
1 file changed +4
-13
lines changed Original file line number Diff line number Diff line change 16
16
package discoverymanager
17
17
18
18
import (
19
- "context"
20
19
"fmt"
21
20
"sync"
22
21
@@ -72,7 +71,6 @@ func (dm *DiscoveryManager) Add(disc *discovery.PluggableDiscovery) error {
72
71
// Returns a list of errors returned by each call of f.
73
72
func (dm * DiscoveryManager ) parallelize (f func (d * discovery.PluggableDiscovery ) error ) []error {
74
73
var wg sync.WaitGroup
75
- ctx , cancel := context .WithCancel (context .Background ())
76
74
errChan := make (chan error )
77
75
for _ , d := range dm .discoveries {
78
76
wg .Add (1 )
@@ -85,23 +83,16 @@ func (dm *DiscoveryManager) parallelize(f func(d *discovery.PluggableDiscovery)
85
83
}
86
84
87
85
// 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.
90
87
go func () {
91
88
wg .Wait ()
92
- cancel ( )
89
+ close ( errChan )
93
90
}()
94
91
95
92
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 )
103
95
}
104
- done:
105
96
return errs
106
97
}
107
98
You can’t perform that action at this time.
0 commit comments