pub struct TimerDriverRegistry { /* private fields */ }Expand description
Host timer drivers keyed by registration order. A driver is owned by a host
context that can die independently
of the process – the Node binding registers one driver per importing napi
env, and a worker’s env teardown kills its driver’s threadsafe function. A
single first-wins slot is therefore unsound: a worker that imports the
binding first and then exits would permanently shadow the slot with a dead
driver, and every CT timer armed afterwards would busy-fail against it.
Selecting only the newest live driver is also
insufficient: a live worker can be CPU-blocked indefinitely while another
environment remains responsive. The registry therefore keeps all
registrants and returns a stable snapshot of every live driver at each
Sleep poll, sweeping dead entries out as it goes.
Instance-based (not a hidden global) so tests exercise
registration/eviction/selection against local registries; production uses
the process-global one behind
register_timer_driver/unregister_timer_driver/has_live_timer_driver.
Implementations§
Source§impl TimerDriverRegistry
impl TimerDriverRegistry
Sourcepub fn register(&self, driver: Arc<dyn TimerDriver>) -> TimerDriverId
pub fn register(&self, driver: Arc<dyn TimerDriver>) -> TimerDriverId
Add driver as the newest registrant and return its handle.
Sourcepub fn unregister(&self, id: TimerDriverId)
pub fn unregister(&self, id: TimerDriverId)
Drop the registration behind id (no-op when already swept/removed).
Sourcepub fn has_live_driver(&self) -> bool
pub fn has_live_driver(&self) -> bool
Whether a LIVE driver is currently registered (dead-only counts as no).
Trait Implementations§
Source§impl Default for TimerDriverRegistry
impl Default for TimerDriverRegistry
Source§fn default() -> TimerDriverRegistry
fn default() -> TimerDriverRegistry
Source§impl Drop for TimerDriverRegistry
impl Drop for TimerDriverRegistry
Auto Trait Implementations§
impl !Freeze for TimerDriverRegistry
impl RefUnwindSafe for TimerDriverRegistry
impl Send for TimerDriverRegistry
impl Sync for TimerDriverRegistry
impl Unpin for TimerDriverRegistry
impl UnsafeUnpin for TimerDriverRegistry
impl UnwindSafe for TimerDriverRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more