lib: Replace done channel with contexts in and add names to util services (#6166)

This commit is contained in:
Simon Frei
2019-11-21 08:41:15 +01:00
committed by GitHub
parent 552ea68672
commit 90d85fd0a2
34 changed files with 240 additions and 218 deletions

View File

@@ -7,6 +7,7 @@
package nat
import (
"context"
"sync"
"time"
)
@@ -19,7 +20,7 @@ func Register(provider DiscoverFunc) {
providers = append(providers, provider)
}
func discoverAll(renewal, timeout time.Duration, stop chan struct{}) map[string]Device {
func discoverAll(ctx context.Context, renewal, timeout time.Duration) map[string]Device {
wg := &sync.WaitGroup{}
wg.Add(len(providers))
@@ -32,7 +33,7 @@ func discoverAll(renewal, timeout time.Duration, stop chan struct{}) map[string]
for _, dev := range f(renewal, timeout) {
select {
case c <- dev:
case <-stop:
case <-ctx.Done():
return
}
}
@@ -50,7 +51,7 @@ func discoverAll(renewal, timeout time.Duration, stop chan struct{}) map[string]
return
}
nats[dev.ID()] = dev
case <-stop:
case <-ctx.Done():
return
}
}