ping: simplify ping loop
@@ -99,11 +99,7 @@ func Ping(ctx context.Context, h host.Host, p peer.ID) <-chan Result {
defer close(out)
defer cancel()
- for {
- select {
- case <-ctx.Done():
- return
- default:
+ for ctx.Err() == nil {
var res Result
res.RTT, res.Error = ping(s)
@@ -123,7 +119,6 @@ func Ping(ctx context.Context, h host.Host, p peer.ID) <-chan Result {
return
}
}
- }
}()
go func() {
// forces the ping to abort.
