Documentation ¶
Overview ¶
Package ttime implements a testable alternative to the Go "time" package.
Index ¶
- func After(t time.Duration) <-chan time.Time
- func Now() time.Time
- func SetTime(t Time)
- func Since(t time.Time) time.Duration
- func Sleep(d time.Duration)
- type DefaultTime
- type TestTime
- func (t *TestTime) After(d time.Duration) <-chan time.Time
- func (t *TestTime) AfterFunc(d time.Duration, f func()) Timer
- func (t *TestTime) Cancel()
- func (t *TestTime) LudicrousSpeed(b bool)
- func (t *TestTime) Now() time.Time
- func (t *TestTime) Sleep(d time.Duration)
- func (t *TestTime) Warp(d time.Duration)
- type Time
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetTime ¶
func SetTime(t Time)
SetTime configures what 'Time' implementation to use for each of the package-level methods.
Types ¶
type DefaultTime ¶
type DefaultTime struct{}
DefaultTime is a Time that behaves normally
func (*DefaultTime) After ¶ added in v1.1.0
func (*DefaultTime) After(d time.Duration) <-chan time.Time
After sleeps for the given duration and then writes to to the returned channel
func (*DefaultTime) AfterFunc ¶ added in v1.3.1
func (*DefaultTime) AfterFunc(d time.Duration, f func()) Timer
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 (*DefaultTime) Sleep ¶
func (*DefaultTime) Sleep(d time.Duration)
Sleep sleeps for the given duration
type TestTime ¶
type TestTime struct { // IsLudicrousSpeed indicates whether sleeps will all succeed instantly IsLudicrousSpeed bool // contains filtered or unexported fields }
TestTime implements a time that is able to be moved forward easily
func NewTestTime ¶
func NewTestTime() *TestTime
NewTestTime returns a default TestTime. It will not be LudicrousSpeed and will behave like a normal time
func (*TestTime) After ¶ added in v1.1.0
After returns a channel which is written to after the given duration, taking into account time-warping
func (*TestTime) AfterFunc ¶ added in v1.3.1
AfterFunc returns a timer and calls a function after a given time taking into account time-warping
func (*TestTime) Cancel ¶ added in v1.3.1
func (t *TestTime) Cancel()
Cancel cancels all pending sleeps
func (*TestTime) LudicrousSpeed ¶
LudicrousSpeed can be called to toggle LudicrousSpeed (default off). When LudicrousSpeed is engaged, all calls to "sleep" will succeed instantly.