Documentation
¶
Overview ¶
Package crock provides mock implementations of functions from the stdlib time package.
crock deliberately does not specify any interfaces or shims for "real" time. Consumers should create their own interfaces, and make a trivial shim to integrate functions from package time into their code.
See the example for some stuff you can lift for this purpose.
Index ¶
- Constants
- type Duration
- type Time
- func (t *Time) After(d time.Duration) <-chan time.Time
- func (t *Time) AfterFunc(d Duration, f func()) *timeproxy.Timer
- func (t *Time) NewTicker(d time.Duration) *timeproxy.Ticker
- func (t *Time) NewTimer(d Duration) *timeproxy.Timer
- func (t *Time) Now() time.Time
- func (t *Time) Set(to time.Time)
- func (t *Time) Since(s time.Time) time.Duration
- func (t *Time) Sleep(d time.Duration)
- func (t *Time) Start()
- func (t *Time) Stop()
- func (t *Time) Tick(d time.Duration) <-chan time.Time
- func (t *Time) Until(s time.Time) time.Duration
Constants ¶
const ( // DefaultResolution is the resolution at which crock time updates. DefaultResolution = time.Second // DefaultMultiplier is the relative speed at which crock time progresses. DefaultMultiplier = 1.0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Time ¶
type Time struct {
// Resolution is the frequency events will be processed at once crock time
// is started.
Resolution time.Duration
// Multiplier controls the relative speed of crock time. A multiplier of
// 1.0 means crock time will proceed at nearly the same speed as real time.
Multiplier float64
// contains filtered or unexported fields
}
Time is a crock implementation of time. New Times are halted by default - they do not advance. Time proceeds according to the resolution and multiplier settings. By default, the Resolution is DefaultResolution and Multiplier is DefaultMultiplier.
Don't change the Resolution and Multiplier fields when time is in motion.
func NewTime ¶
NewTime creates a new time, which is now. Resolution and Multiplier are set to their defaults.
func (*Time) After ¶
After works like time.After, except it only sends on the channel it returns if crock time progresses enough.
func (*Time) NewTicker ¶
NewTicker creates a new crock ticker. It works like time.Ticker, except that it only ticks when time is progressing.
func (*Time) NewTimer ¶
NewTimer creates a new crock timer. It works like time.NewTimer except the timer only sends
func (*Time) Set ¶
Set sets crock time to a particular time. Can be invoked whether or not time is currently progressing. If there are timer or ticker events that would have occurred before the set crock time, they will fire.
func (*Time) Start ¶
func (t *Time) Start()
Start causes crock time to progress at the rate determined by t.Multiplier. For example, if t.Multiplier is 0.5, crock time will progress twice as slowly as real time.
Don't call Start concurrently with other methods.
func (*Time) Stop ¶
func (t *Time) Stop()
Stop stops crock time.
Don't call Stop concurrently with other methods.