Replace calls to time.After with time.NewTimer for explicit stopping

This commit is contained in:
Daniel Smith
2015-05-04 14:29:33 -07:00
parent 838b59cb4d
commit 16a6fb8ef7
6 changed files with 48 additions and 18 deletions

View File

@@ -89,7 +89,12 @@ func poller(interval, timeout time.Duration) WaitFunc {
defer tick.Stop()
var after <-chan time.Time
if timeout != 0 {
after = time.After(timeout)
// time.After is more convenient, but it
// potentially leaves timers around much longer
// than necessary if we exit early.
timer := time.NewTimer(timeout)
after = timer.C
defer timer.Stop()
}
for {
select {