forked from quic-go/quic-go
don't set a timer when the deadline is the zero value
This commit is contained in:
@@ -34,7 +34,9 @@ func (t *Timer) Reset(deadline time.Time) {
|
|||||||
if !t.t.Stop() && !t.read {
|
if !t.t.Stop() && !t.read {
|
||||||
<-t.t.C
|
<-t.t.C
|
||||||
}
|
}
|
||||||
t.t.Reset(time.Until(deadline))
|
if !deadline.IsZero() {
|
||||||
|
t.t.Reset(time.Until(deadline))
|
||||||
|
}
|
||||||
|
|
||||||
t.read = false
|
t.read = false
|
||||||
t.deadline = deadline
|
t.deadline = deadline
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ var _ = Describe("Timer", func() {
|
|||||||
Eventually(t.Chan()).Should(Receive())
|
Eventually(t.Chan()).Should(Receive())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("doesn't set a timer if the deadline is the zero value", func() {
|
||||||
|
t := NewTimer()
|
||||||
|
t.Reset(time.Time{})
|
||||||
|
Consistently(t.Chan()).ShouldNot(Receive())
|
||||||
|
})
|
||||||
|
|
||||||
It("fires the timer twice, if reset to the same deadline", func() {
|
It("fires the timer twice, if reset to the same deadline", func() {
|
||||||
deadline := time.Now().Add(-time.Millisecond)
|
deadline := time.Now().Add(-time.Millisecond)
|
||||||
t := NewTimer()
|
t := NewTimer()
|
||||||
|
|||||||
Reference in New Issue
Block a user