XU XUv0.16.0

#timer

import: #timer

counts: 1 functions, 5 methods, 2 types, 0 constants, 0 method sets

High-density timers for heartbeats / TTL / file RTO. time.AfterFunc / Ticker spawn one sleeper task each. A gateway holding 5k heartbeats must not own 5k tasks. v1 Wheel is **poll-based**: the caller owns the list (no `$&` across `xu`, S6). Typical use is one coordinator task w := timer.new w.after_ns(30 * time.millisecond) w.every_ns(time.second) for { id := w.run // sleeps until next deadline, returns due id... } A background `xu` wrapper can sit on top once channel-of-struct is proven on the self-host path.

struct Item

XuAPI
pub struct Item {

}

Purpose

Item context or state structure.

Public fields

This type has no public fields.

struct Wheel

XuAPI
pub struct Wheel {

}

Purpose

Wheel context or state structure.

Public fields

This type has no public fields.

new

XuAPI
pub fn new() Wheel

Purpose

new creates an empty wheel with 1 ms floor resolution.

Parameters

No arguments are required.

Returns

Wheel — a value of this type

($&Wheel) after_ns

XuAPI
pub fn (w $&Wheel) after_ns(delay_ns int) int

Purpose

after_ns arms a one-shot. Returns id (>0).

Parameters

w $&Wheel
The Wheel instance used by this call (exclusive borrow).
delay_ns int
delay_ns (int)

Returns

int — a value of this type

($&Wheel) every_ns

XuAPI
pub fn (w $&Wheel) every_ns(period_ns int) int

Purpose

every_ns arms a repeating timer.

Parameters

w $&Wheel
The Wheel instance used by this call (exclusive borrow).
period_ns int
period_ns (int)

Returns

int — a value of this type

($&Wheel) cancel

XuAPI
pub fn (w $&Wheel) cancel(id int) bool

Purpose

cancel disarms. Returns true if the id was still armed.

Parameters

w $&Wheel
The Wheel instance used by this call (exclusive borrow).
id int
id (int)

Returns

bool — true or false

($&Wheel) try_due

XuAPI
pub fn (w $&Wheel) try_due() int

Purpose

try_due pops one due id without sleeping. 0 when none.

Parameters

w $&Wheel
The Wheel instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Wheel) run

XuAPI
pub fn (w $&Wheel) run() int

Purpose

run sleeps until the next deadline (or tick), then pops due ids. Returns 0 when nothing is armed (after sleeping one tick).

Parameters

w $&Wheel
The Wheel instance used by this call (exclusive borrow).

Returns

int — a value of this type