From 3d4743d96059f009bff7fa7900b48b7a40a1343e Mon Sep 17 00:00:00 2001 From: Ghanan Gowripalan Date: Fri, 6 Jan 2023 12:51:55 -0800 Subject: [PATCH] Implement null timer NullClock.AfterFunc should not return nil as that violates the API expectations. Instead, return a timer that never fires. PiperOrigin-RevId: 500240130 --- pkg/tcpip/faketime/faketime.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/tcpip/faketime/faketime.go b/pkg/tcpip/faketime/faketime.go index 41a2040a8..81274a4a8 100644 --- a/pkg/tcpip/faketime/faketime.go +++ b/pkg/tcpip/faketime/faketime.go @@ -39,9 +39,22 @@ func (*NullClock) NowMonotonic() tcpip.MonotonicTime { return tcpip.MonotonicTime{} } +// nullTimer implements a timer that never fires. +type nullTimer struct{} + +var _ tcpip.Timer = (*nullTimer)(nil) + +// Stop implements tcpip.Timer. +func (*nullTimer) Stop() bool { + return true +} + +// Reset implements tcpip.Timer. +func (*nullTimer) Reset(time.Duration) {} + // AfterFunc implements tcpip.Clock.AfterFunc. func (*NullClock) AfterFunc(time.Duration, func()) tcpip.Timer { - return nil + return &nullTimer{} } type notificationChannels struct {