type Clock … type FakeClock … // NewRealClock returns a Clock which simply delegates calls to the actual time // package; it should be used by packages in production. func NewRealClock() Clock { … } // NewFakeClock returns a FakeClock implementation which can be // manually advanced through time for testing. The initial time of the // FakeClock will be the current system time. // // Tests that require a deterministic time must use NewFakeClockAt. func NewFakeClock() FakeClock { … } // NewFakeClockAt returns a FakeClock initialised at the given time.Time. func NewFakeClockAt(t time.Time) FakeClock { … } type realClock … func (rc *realClock) After(d time.Duration) <-chan time.Time { … } func (rc *realClock) Sleep(d time.Duration) { … } func (rc *realClock) Now() time.Time { … } func (rc *realClock) Since(t time.Time) time.Duration { … } func (rc *realClock) NewTicker(d time.Duration) Ticker { … } func (rc *realClock) NewTimer(d time.Duration) Timer { … } func (rc *realClock) AfterFunc(d time.Duration, f func()) Timer { … } type fakeClock … type blocker … type expirer … // After mimics [time.After]; it waits for the given duration to elapse on the // fakeClock, then sends the current time on the returned channel. func (fc *fakeClock) After(d time.Duration) <-chan time.Time { … } // Sleep blocks until the given duration has passed on the fakeClock. func (fc *fakeClock) Sleep(d time.Duration) { … } // Now returns the current time of the fakeClock func (fc *fakeClock) Now() time.Time { … } // Since returns the duration that has passed since the given time on the // fakeClock. func (fc *fakeClock) Since(t time.Time) time.Duration { … } // NewTicker returns a Ticker that will expire only after calls to // fakeClock.Advance() have moved the clock past the given duration. func (fc *fakeClock) NewTicker(d time.Duration) Ticker { … } // NewTimer returns a Timer that will fire only after calls to // fakeClock.Advance() have moved the clock past the given duration. func (fc *fakeClock) NewTimer(d time.Duration) Timer { … } // AfterFunc mimics [time.AfterFunc]; it returns a Timer that will invoke the // given function only after calls to fakeClock.Advance() have moved the clock // past the given duration. func (fc *fakeClock) AfterFunc(d time.Duration, f func()) Timer { … } // newTimer returns a new timer, using an optional afterFunc. func (fc *fakeClock) newTimer(d time.Duration, afterfunc func()) *fakeTimer { … } // Advance advances fakeClock to a new point in time, ensuring waiters and // blockers are notified appropriately before returning. func (fc *fakeClock) Advance(d time.Duration) { … } // BlockUntil blocks until the fakeClock has the given number of waiters. // // Prefer BlockUntilContext, which offers context cancellation to prevent // deadlock. // // Deprecation warning: This function might be deprecated in later versions. func (fc *fakeClock) BlockUntil(n int) { … } // BlockUntilContext blocks until the fakeClock has the given number of waiters // or the context is cancelled. func (fc *fakeClock) BlockUntilContext(ctx context.Context, n int) error { … } func (fc *fakeClock) newBlocker(n int) *blocker { … } // stop stops an expirer, returning true if the expirer was stopped. func (fc *fakeClock) stop(e expirer) bool { … } // stopExpirer stops an expirer, returning true if the expirer was stopped. // // The caller must hold fc.l. func (fc *fakeClock) stopExpirer(e expirer) bool { … } // set sets an expirer to expire at a future point in time. func (fc *fakeClock) set(e expirer, d time.Duration) { … } // setExpirer sets an expirer to expire at a future point in time. // // The caller must hold fc.l. func (fc *fakeClock) setExpirer(e expirer, d time.Duration) { … } type firer … func newFirer() firer { … } func (f *firer) Chan() <-chan time.Time { … } // expiry implements expirer. func (f *firer) expiry() time.Time { … } // setExpiry implements expirer. func (f *firer) setExpiry(t time.Time) { … }