API
#timer
Xu 0.8.8 API
import: #timer
counts: 1 fns, 5 methods, 2 types, 0 consts, 0 ifaces
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 `&mut` 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
Purpose
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 `&mut` 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.
Parameters
none
struct Wheel
Purpose
Public struct `Wheel`.
Parameters
none
new
Purpose
new creates an empty wheel with 1 ms floor resolution.
Parameters
none
Returns
Wheel — a value of this type
(&mut Wheel) after_ns
pub fn (w &mut Wheel) after_ns(delay_ns int) int
Purpose
after_ns arms a one-shot. Returns id (>0).
Parameters
w &mut Wheel- receiver &mut Wheel (exclusive borrow)
delay_ns int- delay_ns (int)
Returns
int — a value of this type
(&mut Wheel) every_ns
pub fn (w &mut Wheel) every_ns(period_ns int) int
Purpose
every_ns arms a repeating timer.
Parameters
w &mut Wheel- receiver &mut Wheel (exclusive borrow)
period_ns int- period_ns (int)
Returns
int — a value of this type
(&mut Wheel) cancel
pub fn (w &mut Wheel) cancel(id int) bool
Purpose
cancel disarms. Returns true if the id was still armed.
Parameters
w &mut Wheel- receiver &mut Wheel (exclusive borrow)
id int- id (int)
Returns
bool — true or false
(&mut Wheel) try_due
pub fn (w &mut Wheel) try_due() int
Purpose
try_due pops one due id without sleeping. 0 when none.
Parameters
w &mut Wheel- receiver &mut Wheel (exclusive borrow)
Returns
int — a value of this type
(&mut Wheel) run
pub fn (w &mut 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 &mut Wheel- receiver &mut Wheel (exclusive borrow)
Returns
int — a value of this type