Merge pull request #7737 from lavalamp/fixTimeAfter

Reduce usage of time.After
This commit is contained in:
Wojciech Tyczynski
2015-05-05 09:28:07 +02:00
7 changed files with 49 additions and 19 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 {