pub struct Timers { /* private fields */ }Implementations§
Source§impl Timers
impl Timers
pub fn new() -> Timers
Sourcepub fn restore(&mut self, records: Vec<TimerRecord>)
pub fn restore(&mut self, records: Vec<TimerRecord>)
Adopt restored records.
Sourcepub fn arm(
&mut self,
d: &Durable,
deadline_ms: u64,
owner: Value,
payload: Value,
) -> Result<String, StoreError>
pub fn arm( &mut self, d: &Durable, deadline_ms: u64, owner: Value, payload: Value, ) -> Result<String, StoreError>
Arm a durable timer. owner names who to notify ({"kind": "tool", "node": n, "req": id} / {"kind": "step", "run": r, "step": s} / …).
Sourcepub fn disarm(&mut self, d: &Durable, id: &str) -> Result<(), StoreError>
pub fn disarm(&mut self, d: &Durable, id: &str) -> Result<(), StoreError>
Disarm (delete) a timer — armed or still settling (a cancelled run’s
timers arrive here through owned_by, which reports both, so a row that
fired moments ago is deleted rather than left to re-fire after a restart).
Sourcepub fn fire(&mut self, d: &Durable, now: u64) -> Vec<TimerRecord>
pub fn fire(&mut self, d: &Durable, now: u64) -> Vec<TimerRecord>
Fire every due timer: returns them, removed from the wheel but NOT yet from the store.
The caller runs the effect (on_timer) after this returns, and that
effect is only durable once the same tick reaches its checkpoint.
Deleting the row first opens a window in which a crash loses BOTH the
timer and its consequence: the suspended step the timer owned would have
nothing left to wake it — poll_waits does not look at the timer-backed
wait kinds — so the run wedges forever while the reactor keeps spinning
at its 5 ms floor around a step that can never advance. Effects are
at-least-once by design (RFC 0025 §7: every effect carries an
idempotency key and a replay is expected), so the survivable direction
is the other one — keep the row until the consequence is durable and let
a crash inside the window re-fire the timer on restore.
Sourcepub fn settle(&mut self, d: &Durable)
pub fn settle(&mut self, d: &Durable)
Delete the rows of timers whose effect has been checkpointed. Idempotent (a delete that is lost re-fires the timer once more, which is safe).
Sourcepub fn contains(&self, id: &str) -> bool
pub fn contains(&self, id: &str) -> bool
Whether id is still armed (a settling timer has already fired).
Sourcepub fn next_deadline(&self) -> Option<u64>
pub fn next_deadline(&self) -> Option<u64>
The earliest deadline (for idle decisions).
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn owned_by(&self, pred: impl Fn(&Value) -> bool) -> Vec<String>
pub fn owned_by(&self, pred: impl Fn(&Value) -> bool) -> Vec<String>
Timers owned by something matching pred — armed and settling, so a
cancelled run takes its just-fired rows with it.