Commit 7ccf58e5 authored by vyzo's avatar vyzo

use a timer instead of time.After

parent a6c28389
......@@ -361,9 +361,16 @@ func (s *Swarm) dialWorkerLoop(ctx context.Context, p peer.ID, reqch <-chan Dial
}
var triggerDial <-chan time.Time
var triggerTimer *time.Timer
triggerNow := make(chan time.Time)
close(triggerNow)
defer func() {
if triggerTimer != nil {
triggerTimer.Stop()
}
}()
var nextDial []ma.Multiaddr
active := 0
done := false
......@@ -504,7 +511,15 @@ loop:
// select an appropriate delay for the next dial batch
delay := s.delayForNextDial(lastDial)
triggerDial = time.After(delay)
if triggerTimer == nil {
triggerTimer = time.NewTimer(delay)
} else {
if !triggerTimer.Stop() && triggerDial != triggerTimer.C {
<-triggerTimer.C
}
triggerTimer.Reset(delay)
}
triggerDial = triggerTimer.C
case res := <-resch:
active--
......
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