pub struct IdleGateRegistry { /* private fields */ }Expand description
Registry of subsystem-contributed idle gates.
Implementations§
Source§impl IdleGateRegistry
impl IdleGateRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty registry. The host builds one and registers it as an
IdleGateRegistryHandle.
§Examples
use std::sync::Arc;
use std::time::Duration;
use lattice_mode::idle_gate::IdleGateRegistry;
use tokio::time::Instant;
let gates = Arc::new(IdleGateRegistry::new());
let gate = gates.register("hint", Box::new(Vec::new));
assert_eq!(gates.earliest(), None); // registered disarmed
let t0 = Instant::now();
gate.arm(t0 + Duration::from_millis(300));
assert!(gates.fire_elapsed(t0).is_empty()); // not yet due
gates.fire_elapsed(t0 + Duration::from_millis(300)); // fires, then disarms
assert_eq!(gates.earliest(), None);
drop(gate); // the Guard dropping removes the gateSourcepub fn register(
self: &Arc<Self>,
name: &'static str,
handler: IdleGateHandler,
) -> IdleGateHandle
pub fn register( self: &Arc<Self>, name: &'static str, handler: IdleGateHandler, ) -> IdleGateHandle
Register a gate, disarmed. Returns an RAII handle; dropping it removes the gate.
Sourcepub fn earliest(&self) -> Option<Instant>
pub fn earliest(&self) -> Option<Instant>
The earliest armed deadline, or None when every gate is
disarmed. The actor points its pinned sleep here; None means
park it far out and let the guard keep the arm dormant.
Sourcepub fn fire_elapsed(&self, now: Instant) -> Vec<Effect>
pub fn fire_elapsed(&self, now: Instant) -> Vec<Effect>
Run every gate whose deadline is at or before now, disarming
each as it fires, and return the concatenated Effects.
Disarm-then-run is deliberate: a gate that re-arms itself from inside its own handler must be able to, and it cannot if firing clears the deadline afterwards.
Trait Implementations§
Source§impl Debug for IdleGateRegistry
impl Debug for IdleGateRegistry
Auto Trait Implementations§
impl !Freeze for IdleGateRegistry
impl RefUnwindSafe for IdleGateRegistry
impl Send for IdleGateRegistry
impl Sync for IdleGateRegistry
impl Unpin for IdleGateRegistry
impl UnsafeUnpin for IdleGateRegistry
impl UnwindSafe for IdleGateRegistry
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
Mutably borrows from an owned value. Read more