Documentation
¶
Overview ¶
Package timing provides a demand-driven Hashed Timing Wheel for tracking millions of short-lived timeouts without allocating OS timers.
Concurrency model: Wheel is not thread-safe and must be driven from a single goroutine (e.g., the main game loop).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNegativeAdvance = errors.New("timing wheel advance duration must not be negative")
ErrNegativeAdvance is returned when AdvanceChecked receives a negative delta.
var ErrTimerIDExhausted = errors.New("timing wheel timer ID space exhausted")
ErrTimerIDExhausted is returned rather than reusing a generation and aliasing a stale TimerID.
Functions ¶
This section is empty.
Types ¶
type TimerID ¶
type TimerID uint64
TimerID uniquely identifies a scheduled timer for O(1) cancellation. Upper 32 bits = epoch (generation), Lower 32 bits = slot index.
type Wheel ¶
type Wheel struct {
// contains filtered or unexported fields
}
Wheel is an O(1) hashed timing wheel. It is demand-driven: the caller pumps it by calling Advance(dt).
func New ¶
New creates a timing wheel with the given resolution (tick size). nodeCapacity pre-allocates the fixed-size node pool. It returns nil for invalid dimensions; use NewChecked when the caller needs the error.
func NewChecked ¶ added in v0.37.0
NewChecked creates a timing wheel and reports invalid dimensions.
func (*Wheel) Advance ¶
Advance moves the wheel forward by dt and appends expired payloads to dst. For a negative delta it leaves the wheel unchanged; use AdvanceChecked when the caller needs to observe the validation error.
func (*Wheel) AdvanceChecked ¶ added in v0.37.7
AdvanceChecked advances the wheel and reports invalid negative deltas. Large catch-up intervals are processed in work bounded by the node pool, preserving timer firing order and cancellation cleanup semantics.