From 61f6d50ea9969ef620ea7781c58c1a6be72b9fab Mon Sep 17 00:00:00 2001 From: Miles Delahunty Date: Wed, 20 Oct 2021 14:52:52 +1100 Subject: [PATCH] don't copy time.Timer and Ticker by value --- default.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/default.go b/default.go index f958a5f..7d6fd97 100644 --- a/default.go +++ b/default.go @@ -22,35 +22,35 @@ func (dc DefaultClock) Tick(d time.Duration) <-chan time.Time { return time.Tick // AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method. func (dc DefaultClock) AfterFunc(d time.Duration, f func()) Timer { - return &defaultTimer{*time.AfterFunc(d, f)} + return defaultTimer{time.AfterFunc(d, f)} } // NewTimer creates a new Timer that will send the current time on its channel after at least duration d. func (dc DefaultClock) NewTimer(d time.Duration) Timer { - return &defaultTimer{*time.NewTimer(d)} + return defaultTimer{time.NewTimer(d)} } // NewTicker returns a new Ticker containing a channel that will send the time with a period specified by the duration argument. func (dc DefaultClock) NewTicker(d time.Duration) Ticker { - return &defaultTicker{*time.NewTicker(d)} + return defaultTicker{time.NewTicker(d)} } // Since returns the time elapsed since t. func (dc DefaultClock) Since(t time.Time) time.Duration { return time.Since(t) } -type defaultTimer struct{ time.Timer } +type defaultTimer struct{ *time.Timer } var _ Timer = new(defaultTimer) -func (d *defaultTimer) Chan() <-chan time.Time { +func (d defaultTimer) Chan() <-chan time.Time { return d.C } -type defaultTicker struct{ time.Ticker } +type defaultTicker struct{ *time.Ticker } var _ Ticker = new(defaultTicker) -func (d *defaultTicker) Chan() <-chan time.Time { +func (d defaultTicker) Chan() <-chan time.Time { return d.C }