pub struct TaskGraph { /* private fields */ }Expand description
DAG of tasks with dependency tracking.
Maintains an in-degree counter so ready_tasks() is O(1) amortized.
Implementations§
Source§impl TaskGraph
impl TaskGraph
pub fn new() -> Self
Sourcepub fn add(&mut self, task: RuntimeTask, dependencies: Vec<usize>) -> usize
pub fn add(&mut self, task: RuntimeTask, dependencies: Vec<usize>) -> usize
Add a task, returns its ID. Duplicate dependency entries are collapsed: in_degree counts
entries but complete decrements once per completed dependency, so a
duplicated entry would leave the node permanently below its own in-degree (a silent stall).
Sourcepub fn topological_sort(&self) -> Result<Vec<usize>>
pub fn topological_sort(&self) -> Result<Vec<usize>>
Topological sort — returns ordered IDs or error if cycle detected.
Sourcepub fn ready_tasks(&self) -> Vec<usize>
pub fn ready_tasks(&self) -> Vec<usize>
Return IDs of tasks that are Ready (deps satisfied, not yet started).
Sourcepub fn set_ready(&mut self, task_id: usize)
pub fn set_ready(&mut self, task_id: usize)
Re-mark a (running) task as Ready without touching dependents — used to re-arm a loop node
for its next iteration. Unlike complete, this does NOT decrement any
in-degree, so the loop node’s dependents stay pending until the loop finally completes.
Sourcepub fn complete(&mut self, task_id: usize, result: LoopResult)
pub fn complete(&mut self, task_id: usize, result: LoopResult)
Mark a task as completed; promote dependents whose in-degree reaches 0.
Idempotent: a task already terminal (Completed/Failed) is left untouched — a duplicate completion (at-least-once event delivery, resume replay) must not double-decrement its dependents’ in-degree, which would underflow (debug panic) or over-promote gated nodes.
Sourcepub fn fail(&mut self, task_id: usize)
pub fn fail(&mut self, task_id: usize)
Mark a task as failed (dependents remain Pending — caller decides policy). Terminal states
are sticky: failing an already-completed task must not un-complete it (idempotency twin of
complete).