Skip to main content

TaskNode

Struct TaskNode 

Source
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 str

Human-readable name. Used in defmt logs and panic messages.

§mode: Mode

Lifecycle 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

Source

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.

Source

pub fn shutdown_requested(&self) -> bool

True iff the supervisor has requested shutdown. Checked at the loop top alongside wait_shutdown() in a select.

Source

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.

Source

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.

Source

pub async fn wait_resume(&self)

Pause-mode only: park until the supervisor signals resume.

Source

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.

Source

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.

Source

pub fn is_busy(&self) -> bool

True while this task is actively serving. Read by the scaling policy.

Source

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.

Source

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).

Source

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.

Source

pub fn is_detached(&self) -> bool

True while this node is detached from dependency-cascade teardown.

Source

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).

Trait Implementations§

Source§

impl Debug for TaskNode

Manual impl: the private TaskHandle (Signals + atomics) has no Debug, and a snapshot of the live flags is more useful than raw handle internals anyway. finish_non_exhaustive marks the elided fields (spawn, the handle).

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.