pub trait TimerDriver:
Send
+ Sync
+ 'static {
// Required methods
fn register(&self, id: TimerId, deadline: Instant, waker: Waker);
fn cancel(&self, id: TimerId);
// Provided methods
fn is_live(&self) -> bool { ... }
fn on_swept(&self) { ... }
}Expand description
Seam for host-delegated timers: the CurrentThread flavor cannot park a
helper thread on a threadless build, so it delegates
sleep_until to the host event loop through this trait. The Node binding
installs a setTimeout-based implementation via register_timer_driver
at import – one per importing napi env (main thread AND workers).
Required Methods§
Provided Methods§
Sourcefn is_live(&self) -> bool
fn is_live(&self) -> bool
Whether this driver can still deliver wakes. false once the driver’s
host is gone (the Node binding’s driver dies with its owning napi env:
worker exit aborts the weak threadsafe function). Selection skips and
evicts dead drivers – a timer armed on one would only ever busy-fail.
Sourcefn on_swept(&self)
fn on_swept(&self)
Called by TimerDriverRegistry AFTER it swept this driver out of the
entries (its is_live turned false), with NO registry lock held.
Implementations with pending-waker bookkeeping must wake everything
armed on them here, so those sleeps re-poll onto the next live
registrant: the is_live probe can be the FIRST layer to notice a dying
host (before its env-cleanup hook or any call failure runs), and a
silent retain would strand sleeps whose only wake source was the swept
driver. Idempotent with the owner’s other eviction paths. Default no-op
for drivers without waker state.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".