pub struct TaskNode {
pub name: &'static str,
pub mode: Mode,
pub spawn: Option<fn(Spawner) -> Result<(), SpawnError>>,
/* private fields */
}Expand description
A node in the supervisor’s task graph.
Designed to live in static memory: every field is Sync, all constructors
are const. Declared by supervisor_graph!, which emits one per managed
task along with the Graph (GRAPH) that Supervisor::new consumes.
Fields§
§name: &'static strHuman-readable name. Used in defmt logs and panic messages.
mode: ModeLifecycle policy. See Mode.
spawn: Option<fn(Spawner) -> Result<(), SpawnError>>App-provided spawn function (typically an inline closure at the node’s
declaration). Called once at boot from Supervisor::start, again from
respawn_terminate for Terminate nodes, and at runtime from start_node
for OnDemand nodes. None for a parked node the application spawns
itself (e.g. a Pause sensor holding a peripheral handle): the supervisor
tracks its lifecycle but never spawns it.
Implementations§
Source§impl TaskNode
impl TaskNode
Sourcepub const fn new(
name: &'static str,
mode: Mode,
spawn: Option<fn(Spawner) -> Result<(), SpawnError>>,
disabled_at_boot: bool,
) -> Self
pub const fn new( name: &'static str, mode: Mode, spawn: Option<fn(Spawner) -> Result<(), SpawnError>>, disabled_at_boot: bool, ) -> Self
A single-instance node started at boot (Terminate/Pause) or on demand
(Mode::OnDemand). Every node is single-instance; an elastic service is
modelled as several OnDemand nodes of the same pooled task fn.
A TaskNode carries only its own identity and behaviour; the graph’s
dependency edges live in the compile-time index table that
supervisor_graph! emits and Supervisor::new consumes.
disabled_at_boot seeds the node’s disabled flag so a control-started node
(e.g. an OTA task) can be declared down and started later via a control op.
spawn is None for a parked node the application spawns itself.
Sourcepub fn shutdown_requested(&self) -> bool
pub fn shutdown_requested(&self) -> bool
True iff the supervisor has requested shutdown. Checked at the loop top
alongside wait_shutdown() in a select.
Sourcepub async fn wait_shutdown(&self)
pub async fn wait_shutdown(&self)
Park until shutdown is requested. Returns immediately if shutdown has
already been requested. Use this for single-instance tasks in a select
against the task’s main work future.
Sourcepub fn ack_dropped(&self)
pub fn ack_dropped(&self)
Mark this instance as having shut down: clears the running flag and acks
the teardown handshake (so the supervisor’s wait_dropped completes).
Every instance must call this exactly once on exit (Terminate/OnDemand
mode) or on each pause (Pause mode). It also covers an autonomous exit
the supervisor didn’t request — e.g. a pool worker backing off — so the
pool sees the instance as down and can re-grow it under later demand.
Sourcepub async fn wait_resume(&self)
pub async fn wait_resume(&self)
Pause-mode only: park until the supervisor signals resume.
Sourcepub fn mark_busy(&self)
pub fn mark_busy(&self)
Report that this task started serving a request (active). Fires the scale-request signal on a real idle→busy transition so the scaling policy can react (e.g. grow the pool); a redundant call doesn’t re-signal.
Sourcepub fn mark_idle(&self)
pub fn mark_idle(&self)
Report that this task finished serving and is idle again. Fires the scale-request signal on a real busy→idle transition so the scaling policy can react (e.g. shrink the pool); a redundant call doesn’t re-signal.
Sourcepub fn is_busy(&self) -> bool
pub fn is_busy(&self) -> bool
True while this task is actively serving. Read by the scaling policy.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
True while the supervisor has this node spawned (and it hasn’t exited). Read by the scaling policy to count live instances, and by a task-state view.
Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
True while the node has been manually deactivated via the control interface and not yet re-activated. Read by a task-state view and by the automatic bring-up paths (which skip a disabled node).
Sourcepub fn set_detached(&self, detached: bool)
pub fn set_detached(&self, detached: bool)
Mark/clear this node as detached: a node that manages its own lifecycle and must not be torn down by a dependency cascade (see the field doc). Set it before stopping a dependency the node has declared but intends to outlive.
Sourcepub fn is_detached(&self) -> bool
pub fn is_detached(&self) -> bool
True while this node is detached from dependency-cascade teardown.
Sourcepub fn set_disabled(&self, disabled: bool)
pub fn set_disabled(&self, disabled: bool)
Set/clear the manual-deactivation flag. Set by Supervisor::deactivate,
cleared by Supervisor::activate. Deliberately not touched by
reset(), so a manual stop survives respawn cycles and RAM-retaining
power-state transitions.
Public so an application can pre-disable a Terminate node before
Supervisor::start, making it a stopped-at-boot task that only comes up on
an explicit Activate control (a node started by control rather than at boot).