pub struct WaitIndex { /* private fields */ }Expand description
One HashMap keyed by WaitKey rather than one map per condition kind (the spec’s §3
sketch shows several typed buckets): a single generic index is simpler to keep correct and
still answers “who is waiting on this key” in O(1) average, which is the actual requirement.
Implementations§
Source§impl WaitIndex
impl WaitIndex
pub fn new() -> Self
pub fn insert(&mut self, task_id: TaskId, condition: &WaitCondition)
pub fn remove(&mut self, task_id: &TaskId, condition: &WaitCondition)
pub fn lookup(&self, key: &WaitKey) -> &[TaskId] ⓘ
Sourcepub fn wake(&mut self, key: &WaitKey) -> Vec<TaskId> ⓘ
pub fn wake(&mut self, key: &WaitKey) -> Vec<TaskId> ⓘ
spc_003-06 / spec §3: “Effect E completed → WaitIndex[E] → wake task” — the general wake
primitive every event-arrival path uses. Removes and returns every task waiting on exactly
key. Idempotent by construction: waking an already-empty (or never-registered) key finds
nothing and returns [], which is what makes a redelivered/duplicate completion event safe
— a second wake for the same key is a harmless no-op, not a second transition.
Sourcepub fn register_wait_set(&mut self, task_id: TaskId, wait_set: WaitSet)
pub fn register_wait_set(&mut self, task_id: TaskId, wait_set: WaitSet)
spc_003 debt closure / spec §4: register task_id against every condition in wait_set
(via the existing Self::insert, so each condition gets the same O(1)-average key
indexing every other wait does) and track the set itself so Self::notify can evaluate
WaitMode::Any/WaitMode::All satisfaction as individual conditions fire.
Sourcepub fn notify(&mut self, key: &WaitKey) -> Vec<TaskId> ⓘ
pub fn notify(&mut self, key: &WaitKey) -> Vec<TaskId> ⓘ
spc_003 debt closure: notify every task registered under key (via
Self::register_wait_set) that this condition fired, and return the ones whose whole
WaitSet is now satisfied (Any ⇒ this condition alone; All ⇒ every condition fired).
A task not yet fully satisfied stays registered under its remaining keys — this is the one
difference from Self::wake, which always unconditionally removes on any hit. A task
with no tracked WaitSet (i.e. one only ever registered through Self::insert directly)
is not touched here — call Self::wake for that path, as before.
Sourcepub fn expire_timers(&mut self, now_ms: u64) -> Vec<TaskId> ⓘ
pub fn expire_timers(&mut self, now_ms: u64) -> Vec<TaskId> ⓘ
spc_003-05: remove and return every task waiting on a Timer whose deadline has passed
(deadline <= now_ms), matching the now_ms >= deadline expiry predicate used elsewhere
in this crate (signals/queue.rs::escalate_deadlines). Built on Self::wake — expiry is
just “wake every due Timer key,” nothing bespoke.