Commit f1b68880 authored by Steven Allen's avatar Steven Allen

fix(swarm): use the go fork/join idiom

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent 29161484
......@@ -509,17 +509,6 @@ func resolveAddresses(ctx context.Context, addrs []string) ([]ma.Multiaddr, erro
resolveErrC := make(chan error, len(addrs))
maddrC := make(chan ma.Multiaddr)
go func() {
for {
select {
case maddr, ok := <-maddrC:
if !ok {
return
}
maddrs = append(maddrs, maddr)
}
}
}()
for _, addr := range addrs {
maddr, err := ma.NewMultiaddr(addr)
......@@ -553,10 +542,14 @@ func resolveAddresses(ctx context.Context, addrs []string) ([]ma.Multiaddr, erro
}
}(maddr)
}
// wait for address resolving
wg.Wait()
// close the channel of collecting multiaddr
close(maddrC)
go func() {
wg.Wait()
close(maddrC)
}()
for maddr := range maddrC {
maddrs = append(maddrs, maddr)
}
select {
case err := <-resolveErrC:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment