Documentation
¶
Overview ¶
Package clock provides an injectable time source for testable code.
Consumers that need to advance time in tests hold a Clock rather than calling time.Now directly. Production uses Real; tests use Frozen. Both satisfy the Clock interface.
Package-level Now/Since/Sleep back onto a swappable default so consumers who do not want to thread a Clock through their code can still substitute one in tests via SetDefault.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefault ¶
func SetDefault(c Clock)
SetDefault installs c as the package-level clock. Test setup functions typically call SetDefault(NewFrozen(...)) then restore Real on cleanup.
Types ¶
type Frozen ¶
type Frozen struct {
// contains filtered or unexported fields
}
Frozen is a Clock whose Now advances only when Advance is called. Sleep is a no-op unless Advance runs concurrently. Safe for concurrent use.