Documentation
¶
Overview ¶
Package clock provides a minimal Clock interface for time-dependent code. Production code uses Real (which delegates to the standard library), while tests use Mock to advance time programmatically without sleeping.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface {
// NewTicker returns a ticker that fires at the given interval.
NewTicker(d time.Duration) Ticker
// After returns a channel that receives after duration d.
After(d time.Duration) <-chan time.Time
}
Clock abstracts time operations so that tests can control time progression without sleeping. Only operations actually used in the codebase are included.
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock is a deterministic Clock for tests. Time only advances when Add is called, making tests that depend on tickers or timers run instantly.
func (*Mock) Add ¶
Add advances the mock clock by d, firing any tickers or After channels whose deadlines have been reached.
type Real ¶
type Real struct{}
Real is a Clock backed by the standard library's time package.
func (Real) After ¶
After returns a channel that receives after duration d.
WARNING: The returned timer cannot be stopped by the caller. If the channel is never consumed (e.g., due to context cancellation), the timer will not be garbage collected until it fires. Only use this in select statements where the channel is guaranteed to be drained or the goroutine exits promptly.