Documentation
¶
Overview ¶
Package clock provides a small time abstraction so that time-stamped state (a sprite's creation time, and any future timed behavior) can be driven deterministically in tests. Production code uses Real(); tests use a Fake whose Advance method fires scheduled callbacks without any real sleeping.
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 as seen by this clock.
Now() time.Time
// AfterFunc schedules fn to run after d has elapsed and returns a Timer
// that can cancel it.
AfterFunc(d time.Duration, fn func()) Timer
}
Clock is the subset of the time package that spritzer depends on.
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is a deterministic Clock. Time only moves when Advance is called, at which point any callbacks whose deadline has passed run synchronously on the calling goroutine. Callbacks may schedule further callbacks, which are also fired if they fall within the advanced window.
func NewFake ¶
NewFake returns a Fake clock started at the given time. If start is the zero value a fixed, readable epoch is used.
func (*Fake) Advance ¶
Advance moves the clock forward by d, firing every due callback in deadline order. Callbacks run without the internal lock held so they may schedule more work on the same clock.