Documentation
¶
Overview ¶
Package clock is the injectable time source for logic packages: they take a Clock instead of calling time.Now or time.NewTimer, and tests drive a Fake.
rules.Clock has the same Now() time.Time method, so a clock.Clock satisfies it; the two should converge on this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface {
Now() time.Time
// NewTimer returns a timer that fires once, d from now (at once when d <= 0).
NewTimer(d time.Duration) Timer
// NewTimerAt returns a timer that fires once the clock reaches deadline (at once if it
// already has). Code that computed a deadline from an earlier Now uses it, so the time
// that passed since isn't added to the wait.
NewTimerAt(deadline time.Time) Timer
}
Clock reads the time and arms timers.
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is a clock that only moves when told to. Its timers fire during Advance or Set, in deadline order. It is safe for concurrent use.
func (*Fake) Advance ¶
Advance moves the clock forward by d, fires the timers that are due, and returns the new time.
func (*Fake) BlockUntil ¶
BlockUntil waits until at least n timers are waiting to fire, so a test can Advance only once the code under test is waiting on the clock.
func (*Fake) NewTimer ¶
NewTimer returns a timer that fires once the clock reaches now+d (at once when d <= 0).
func (*Fake) NewTimerAt ¶
NewTimerAt returns a timer that fires once the clock reaches deadline.
type Real ¶
type Real struct{}
Real is the wall clock.
func (Real) NewTimerAt ¶
NewTimerAt is NewTimer(time.Until(deadline)).