Skip to content

Commit 339702a

Browse files
authored
Merge pull request robfig#60 from sparrc/after-to-timer
Use time.Timer instead of time.After
2 parents c1becd4 + f0a137d commit 339702a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cron.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ func (c *Cron) run() {
165165
effective = c.entries[0].Next
166166
}
167167

168+
timer := time.NewTimer(effective.Sub(now))
168169
select {
169-
case now = <-time.After(effective.Sub(now)):
170+
case now = <-timer.C:
170171
// Run every entry whose next time was this effective time.
171172
for _, e := range c.entries {
172173
if e.Next != effective {
@@ -186,11 +187,13 @@ func (c *Cron) run() {
186187
c.snapshot <- c.entrySnapshot()
187188

188189
case <-c.stop:
190+
timer.Stop()
189191
return
190192
}
191193

192194
// 'now' should be updated after newEntry and snapshot cases.
193195
now = time.Now().Local()
196+
timer.Stop()
194197
}
195198
}
196199

0 commit comments

Comments
 (0)