Documentation
¶
Overview ¶
Package clock is the clock capability: the kernel I/O tier's time source. Reading the clock and waiting for an instant are system calls whose far side is the kernel, so a service that schedules by time does both through a capability granted by the binary that owns the process, never through package time directly. The binary grants SystemClock; a spec grants a ManualClock and moves time itself, so a wait for the next occurrence is proven without a sleep.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IClock ¶
type IClock interface {
// Now is the current instant.
Now() time.Time
// After delivers the instant at which d elapsed; a zero or negative d
// delivers at once. The channel is buffered to one and never closed, as
// time.After's is.
After(d time.Duration) <-chan time.Time
}
IClock is the time source a service is granted: the current instant, and a wait that delivers once a duration has elapsed.
type ManualClock ¶
type ManualClock struct {
// contains filtered or unexported fields
}
ManualClock is a clock that moves only when its owner moves it: the in-process substitute a spec grants instead of SystemClock. Every After arms a wait at the current instant plus its duration; ManualClock.Advance fires the waits the new instant has reached, earliest first, delivering as time.After does, into a one-slot buffer without blocking.
The zero value is not usable; construct it with NewManualClock. Its methods are safe to call from the goroutine under test and the spec at once.
func NewManualClock ¶
func NewManualClock(start time.Time) *ManualClock
NewManualClock returns a clock reading start.
func (*ManualClock) Advance ¶
func (clock *ManualClock) Advance(d time.Duration)
Advance moves the clock forward by d and fires every armed wait whose deadline the new instant has reached, earliest first, each with its own deadline. A wait nobody has drained since it last fired is dropped, as time.After's would be.
func (*ManualClock) After ¶
func (clock *ManualClock) After(d time.Duration) <-chan time.Time
After arms a wait that fires once Advance has moved the clock to its deadline. A deadline not after the current instant fires at once, as time.After(0) does.
func (*ManualClock) Now ¶
func (clock *ManualClock) Now() time.Time
Now is the instant the clock was last moved to.
func (*ManualClock) Waiting ¶
func (clock *ManualClock) Waiting() int
Waiting reports how many waits are armed and not yet fired, so a spec can let the code under test arm its wait before advancing past it.
type SystemClock ¶
type SystemClock struct{}
SystemClock is the host's clock: package time behind the capability.
func NewSystemClock ¶
func NewSystemClock() SystemClock
NewSystemClock grants the host's clock as its own concrete type; a caller that wants the abstraction assigns it into an IClock (CS-8).