Skip to main content

TimerRuntime

Trait TimerRuntime 

Source
pub trait TimerRuntime {
    type TimerId;

    // Required methods
    fn set_timer(&mut self, id: Self::TimerId, duration: Duration);
    fn kill_timer(&mut self, id: Self::TimerId);
}
Expand description

A runtime that can set and kill timers.

The state machine produces TimerCommands in its Response. The runtime implements this trait to translate those commands into actual platform timer operations.

§Invariant: Set resets an existing timer

Implementations must ensure that calling set_timer with an ID that already has an active timer replaces that timer rather than creating a second concurrent timer for the same ID. The new timer starts counting from the moment set_timer is called.

§Platform examples

Platformset_timerkill_timer
WindowsSetTimer() (reuses the same nIDEvent)KillTimer()
Linuxtimerfd_settime() (overwrites existing armed state)timerfd_settime(0)
macOSCFRunLoopTimerSetNextFireDate() (adjusts fire date)invalidate the CFRunLoopTimerRef
Testrecord to Vecrecord to Vec

Required Associated Types§

Source

type TimerId

The timer identifier type (must match the state machine’s TimerId).

Required Methods§

Source

fn set_timer(&mut self, id: Self::TimerId, duration: Duration)

Start or restart a timer.

If a timer with the same ID is already active, it must be reset to the new duration — only one timer per ID may be active at a time.

Source

fn kill_timer(&mut self, id: Self::TimerId)

Stop an active timer. No-op if the timer is not active.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§