Documentation
¶
Index ¶
- func After(d time.Duration) <-chan time.Time
- func Now() time.Time
- func Override(implementation Implementation) func()
- func Since(t time.Time) time.Duration
- func Sleep(d time.Duration)
- func Until(t time.Time) time.Duration
- type Default
- func (Default) After(d time.Duration) <-chan time.Time
- func (Default) AfterFunc(d time.Duration, f func()) Timer
- func (Default) NewTicker(d time.Duration) Ticker
- func (Default) NewTimer(d time.Duration) Timer
- func (Default) Now() time.Time
- func (Default) Since(t time.Time) time.Duration
- func (Default) Sleep(d time.Duration)
- func (Default) Until(t time.Time) time.Duration
- type Implementation
- type Ticker
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Override ¶
func Override(implementation Implementation) func()
Override replaces the global implementation used for timex The returned function should be called to restore the default implementation
Types ¶
type Default ¶ added in v1.1.0
type Default struct{}
Default uses time package functions
func (Default) AfterFunc ¶ added in v1.1.0
AfterFunc can be used as a replacement of time.AfterFunc()
func (Default) NewTicker ¶ added in v1.1.0
NewTicker creates a new ticker as replacement of time.NewTicker()
func (Default) NewTimer ¶ added in v1.1.0
NewTimer creates a new timer as replacement of time.NewTimer()
type Implementation ¶
type Implementation interface { Now() time.Time Since(t time.Time) time.Duration Until(t time.Time) time.Duration Sleep(d time.Duration) After(d time.Duration) <-chan time.Time AfterFunc(d time.Duration, f func()) Timer NewTicker(d time.Duration) Ticker NewTimer(d time.Duration) Timer }
Implementation defines the methods we delegate
type Ticker ¶
type Ticker interface { // C returns the channel where each tick will be signaled, like Ticker.C in time package C() <-chan time.Time // Stop stops the ticker, no more ticks will be received in `C()` Stop() }
Ticker is an interface similar to what time.Ticker provides, but with C as a function returning the channel instead of accessing a plain struct property, so we can mock it. See time.Ticker docs for more details
type Timer ¶
type Timer interface { // C returns the channel where the tick will be signaled, like Timer.C in time package C() <-chan time.Time // Stop stops the timer, see exact docs on time.Timer for information about channel draining when Stop returns false Stop() bool }
Timer is an interface similar to what time.Timer provides, but with C as a function returning the channel instead of accessing a plain struct property, so we can mock it. See time.Timer docs for more details