timing

package
v0.31.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

This section is empty.

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

func New(resolution time.Duration, slots, nodeCapacity int) *Wheel

New creates a timing wheel with the given resolution (tick size). nodeCapacity pre-allocates the fixed-size node pool.

func (*Wheel) Advance

func (w *Wheel) Advance(dt time.Duration, dst []any) []any

Advance moves the wheel forward by dt and appends expired payloads to dst.

func (*Wheel) Cancel

func (w *Wheel) Cancel(id TimerID) bool

Cancel removes a scheduled timer in O(1) time without allocations.

func (*Wheel) Schedule

func (w *Wheel) Schedule(delay time.Duration, payload any) (TimerID, error)

Schedule adds a timeout. Returns an error if the node pool is exhausted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL