Documentation
¶
Overview ¶
Package fakeclock is a clock that a test moves by hand, so that timers and frame times in tests need no 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.
Now() time.Time
// AfterFunc runs f in its own goroutine (the real clock) or inside Advance
// (the fake one) after d. The returned Timer cancels it.
AfterFunc(d time.Duration, f func()) Timer
}
Clock tells the time and runs functions later. The real clock and the fake one both implement it, and code that needs time takes a Clock.
Flutter: no counterpart (flutter_test's FakeAsync)
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is a Clock that only moves when Advance or Set is called. It is safe for concurrent use; the functions run on the goroutine that advances it.
Flutter: no counterpart (flutter_test's FakeAsync)
func New ¶
New returns a fake clock that reads start. A zero start is the Unix epoch, so that times print the same on every run.
func (*Fake) Advance ¶
Advance moves the clock forward by d and runs the timers that come due, in order of their time (and of their creation for equal times). While a function runs the clock reads the time of its timer, so a function that reads the clock or sets another timer sees a consistent time; a timer it sets that falls within d runs in the same call. A negative d panics.
func (*Fake) AfterFunc ¶
AfterFunc schedules f to run when the clock has advanced by d. A d of zero or less runs f at the next Advance (of any amount, including zero).