Expand description
Dependency-ordered task-lifecycle supervision for embassy firmware.
embassy-supervisor brings tasks up in dependency order, supervises their
lifecycle (Terminate, Pause, OnDemand), tears dependents down before
the things they depend on, and verifies declared dataflow against live
behaviour. The graph is declared through the supervisor_graph! macro
(re-exported from embassy-supervisor-macros) and checked at compile time.
The crate is HAL-agnostic, no_std, and has no allocator or board-specific
dependencies.
Modules§
- shape
- Structural facts about a graph, as bits in
Topology::SHAPE— what the graph contains, decided atsupervisor_graph!expansion and carried in the topology’s type, so lifecycle code serving an absent structure is - trace
- Runtime tracing hooks and task introspection helpers.
Macros§
- compose_
graph - Compose a graph out of one or more
supervisor_fragment!declarations. - supervisor_
fragment - supervisor_
graph
Structs§
- Aborted
- The shutdown side of
TaskNode::run_cancellable’s result: the raced work future was cancelled at its await point because a stop/pause request won the select. Pairs naturally with theexit:slot — a worker returningResult<R, Aborted>records completed-vs-cancelled for whoever reads the exit value. - Backed
- A signal whose producer is started by the first reader that calls
open. The value is not handed out until the producer is running and ready. The gate counts readers so the producer can retire once none are left (unwatched,TaskNode::retire). - Budget
- A budget of
u32units divided amongNclaimant slots. - Claimant
- A holder’s handle on one slot of a
Budget: what adivisibleentry hands the worker.Copy, so a worker may keep one per loop it runs. - Control
Command - A control request addressed to a specific node.
- Control
Queue Full - The control mailbox was full (4 outstanding requests) and the request was
not enqueued. Returned by
try_request_control; retry after the supervisor’s driver loop has drained a command, or use the awaitingrequest_controlfrom async contexts. - Coupling
- A declared read/write coupling between a node and a signal.
- Deferred
Shrink - A scaling policy that grows immediately but shrinks only after a cooldown.
- Elastic
Pool - An elastic pool backed by a
ScalingPolicy. - Fair
Share - Every holder gets its want when the capacity covers the sum; otherwise the capacity is split in proportion to the wants, with the integer remainder handed one unit at a time to the lowest slots that can use it. Changes apply immediately in both directions.
- Flat
- The
Topologyof a graph with nodeps:edges anywhere: zero-sized, every dep list is empty by type, and the topological order is declaration order. The walks aSupervisorruns over it fold to plain index loops, and the dependency cascades (activate,deactivate,restart) collapse to their seed sets. - Graph
- A static task graph: the nodes, the topology over them, and optional pools.
- Graph
Ref - A reference to a registered graph, used for runtime introspection.
- Graphs
- Iterator over registered graphs returned by
graphs. - Health
Event - One observation from
Supervisor::monitor, delivered throughwait_health. - Lease
- A live claim on a
Leasedsignal: the producer’sdraindoes not return until everyLeasehas been dropped. - Leased
- A signal-like value whose producer can wait until all outstanding readers finish.
- NodeCfg
- The immutable half of a
TaskNode: everything the graph declared about the node, none of what happens to it at runtime. No interior mutability, so thestaticcarrying it lives in flash (.rodata); the RAM-resident node points at it. Builtconstwithnewplus the chainablewith_*methods, exactly assupervisor_graph!emits it. - Node
Fault - A node-scoped lifecycle failure: which node, and what went wrong.
- Observer
- A callable that returns a signal’s change count for observation.
- Open
- A reader’s hold on a
Backedsignal, fromopen.Derefgives the wrapped signal’s API; dropping the guard lets the producer notice the last reader has left. - Ordered
- A
Topologywhose nodes are topologically sorted by theirdeps:edges. - Pool
Stats - Snapshot of an elastic pool’s current load.
- Resource
Slot - A one-value handoff cell threading an owned resource from
maininto a supervised task — the safe replacement forPeripherals::steal()inside the task body. - Resumed
- The pause side of
TaskNode::run_pausable’s result: a stop/pause request won the race, the combinator acked and parked, and the supervisor has since resumed the node. By the time a body seesErr(Resumed)the park is already over — the next loop iteration is the fresh cycle. - Shrink
Fast Grow Slow FairShare’s division, applied asymmetrically: a cut lands at once, an increase is ramped at moststepunits perinterval. The safety shape of a shared power or bandwidth budget — a holder must never be granted more than the budget can carry, so reductions cannot wait, while a holder drawing more can wait for the others to have backed off.- Sig
- A typed handle to a signal declared in a
reads:/writes:list. - Spawner
Slot - Runtime-filled slot holding a foreign executor’s
SendSpawner. - Stamped
- A signal wrapper that stamps every write with the time it happened, so a reader can ask how old the value is.
- Supervisor
- Orchestrates a set of managed tasks across spawn / teardown / bring-up.
- Task
Handle - Coordination state for one task. Embedded inside
TaskNode. - Task
Node - A node in the supervisor’s task graph.
- Veto
- One writer’s handle on its slot of a
VetoGate, fromTaskNode::veto. - Veto
Gate - A gate that is asserted while any of its
Ncontributors holds it and released only once all of them have let go.
Enums§
- Control
Op - A control request issued to the supervisor for a node.
- Fault
- A fault injected into a node through
TaskNode::inject. The verbs act on the task, not the worker. - Fault
Kind - What went wrong in a
NodeFault. - Health
Kind - What the monitor observed about a node.
- Inject
Error - Why
TaskNode::injectrefused. - Mode
- Lifecycle policy for a managed task: what the task does on shutdown and what the supervisor does to bring it back.
- Pool
Action - Action the supervisor should take for a pool member.
- Scale
Action - Decision an elastic scaling policy can return.
Traits§
- Budget
Policy - How a
Budget’s capacity is divided over its holders’ wants. - Coupling
Point - A signal a node declares it reads or writes.
- Divisible
- The object-safe view of a
BudgetaClaimantand a node’s claims table go through, so neither namesN. - Gated
- A signal whose producer must be running and ready before a reader can use it.
- Observable
- A type whose writes can be observed without interpreting the value.
- Pool
- Object-safe, synchronous pool interface so
&dyn Poolneeds no heap: the policy decides here; the supervisor performs the async start/stop. Object-safe, synchronous pool interface used by the supervisor. - Resource
Gate - Type-erased readiness view of a
ResourceSlot, for the supervisor’s bring-up wait. - Scaling
Policy - Policy that decides when an elastic pool should grow or shrink.
- Sink
- A signal that can be written through the supervisor’s
putverb. - Source
- A signal that can be read through the supervisor’s
getverb. - Topology
- Structural information about a graph, used by
Supervisorto decide which lifecycle code paths can be compiled out. - Zeroable
- Trait for types that can be safely created with
zeroed.
Functions§
- graphs
- Return an iterator over every registered graph, most recent first.
- init_
host_ logging - Call once from a simulator’s or test’s
mainbefore the supervisor starts; records emitted earlier are dropped by thelogfacade. Errors if a logger is already installed — including a second call — in which case the existing logger and level are left untouched. - producer_
of - Find the node that writes to
entry, if there is exactly one. - request_
control - Enqueue a control request, waiting for mailbox capacity if it is full. Lossless — the request is delivered once the supervisor’s driver loop drains an earlier command. Called by the application’s control surface.
- request_
scale - Signal that an elastic pool should re-evaluate its scaling decision.
- try_
request_ control - Non-blocking variant of
request_controlfor sync contexts (ISRs, callbacks). Fails withControlQueueFullinstead of dropping the request when the mailbox is full — the caller decides whether to retry or surface it. - try_
wait_ health - Non-blocking
wait_health, for a consumer that polls (a status endpoint draining pending events, an existing loop that must not park here). - wait_
bind - Await the next readiness transition of any node. The supervisor’s driver loop selects this alongside pool scaling and control.
- wait_
control - Await the next control request. Selected by the supervisor’s driver loop against pool scaling and any other application wake sources.
- wait_
health - Await the next health observation from
Supervisor::monitor. - wait_
scale - Wait until something requests a pool scaling re-evaluation.