Documentation
¶
Overview ¶
Package clock is the time source every scheduling decision reads. Logic in this module never calls time.Now or time.NewTimer: it takes a Clock, so production passes Real and tests pass a Fake that moves only when told to, which makes "sleep three days" run in microseconds and makes every run repeatable.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface {
// Now returns the current time.
Now() time.Time
// NewTimer returns a timer that delivers on C once d has passed. A d
// of zero or less fires at once.
NewTimer(d time.Duration) Timer
}
Clock is a source of the current time and of timers.
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is a Clock that moves only on Advance or Set. Timers due at or before the new time fire in deadline order, each receiving its deadline. It is safe for concurrent use. Use NewFake; the zero value is not ready.
func (*Fake) Advance ¶
Advance moves the clock forward by d and fires every timer now due. A negative d is ignored: the fake clock never goes back.
func (*Fake) BlockUntil ¶
BlockUntil waits until at least n timers are pending, so a test can Advance only after the goroutine under test has armed its timer. It returns ctx.Err() if ctx ends first.
func (*Fake) NewTimer ¶
NewTimer returns a timer due at Now()+d. A d of zero or less fires at once, as time.NewTimer does.
type Real ¶
type Real struct{}
Real is the wall clock. It is the one place in this module that reads time.Now.
type Timer ¶
type Timer interface {
// C delivers the fire time once. Its buffer holds one value, so a
// timer never blocks the clock that fires it.
C() <-chan time.Time
// Stop prevents the timer from firing. It reports whether it did so,
// false when the timer had already fired or been stopped.
Stop() bool
}
Timer is a one-shot timer.