Skip to content

Commit da6a910

Browse files
committed
Non-blocking write to the timer channel
In case the user calls Reset without draining the channel.
1 parent fa525c8 commit da6a910

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

clock.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,12 @@ func (t *internalTimer) Tick(now time.Time) {
350350
// defer function execution until the lock is released, and
351351
defer func() { go t.fn() }()
352352
} else {
353-
t.c <- now
353+
// it's possible to reset the clock without draining the channel. Don't block in
354+
// that case.
355+
select {
356+
case t.c <- now:
357+
default:
358+
}
354359
}
355360
t.mock.removeClockTimer((*internalTimer)(t))
356361
t.stopped = true

0 commit comments

Comments
 (0)