Expand description
M:N flows, mailboxes, timer, supervisor and Runtime.
A flow is Byteflow’s unit of concurrent work (not an OS thread). Flows
exchange Atomic Hops (crate::Value::Message) — never bare scalars
on bytecode Send / Ask.
§Authority boundary
The VM only validates types. This module owns delivery:
- Resolve
crate::Value::Cap→FlowId+ rights (CapRights) - Stamp
Message.senderand mintreply_cap(SEND-only) - Push into the target
Mailbox(anti lost-wakeup under one mutex)
crate::Value::Pid is identity inside hops, not an ambient address.
Host Runtime::send takes FlowId directly (trusted).
Structs§
- CapId
- Opaque capability identifier carried in
crate::Value::Cap. - CapRights
- Rights attached to a capability (bitflags as
u8). - Child
Spec - A child the supervisor should start (and possibly restart).
- Flow
- A single flow: VM state, mailbox, and bookkeeping.
- Flow
Handle - A reference to a spawned flow, returned by
super::runtime::Runtime::spawn. - FlowId
- Identifier of a flow — Byteflow’s unit of concurrent work.
- Flow
Metrics - Live counters for one flow (updated only by the worker currently running it).
- Mailbox
- A flow’s inbox, plus (when the owning flow is blocked on
Receive/ReceiveMatch/Askwith nothing to read) the parked flow itself. - Runtime
- A running Byteflow runtime: worker pool + timer thread over one shared
Chunk. - Runtime
Config - Tunables for
Runtime::new. Everything has a sensible default viaRuntimeConfig::defaultso the common case isRuntime::new(chunk). - Runtime
Metrics - Runtime-wide counters (design notes §26). Every field is a plain
AtomicU64bumped withRelaxedordering: these are monitoring counters, not synchronization primitives, so we don’t pay for anything stronger than “eventually visible to a metrics scrape.” - Runtime
Metrics Snapshot - Point-in-time, non-atomic copy of
RuntimeMetricssuitable for printing or exporting. - Runtime
Spawner - A
Send + Sync, freely cloneable capability to spawn processes into aRuntime, detached from theRuntimevalue itself. Exists becausesuper::supervisor::Supervisorneeds to respawn processes from a background monitor thread whose lifetime isn’t tied to theRuntimeobject’s own (which owns non-SyncJoinHandles for its workers). - Supervisor
- Host-side child restarter (design notes §15-16).
- Supervisor
Config - Tunables for
Supervisor::with_config.
Enums§
- Delivery
- Outcome of pushing a message: either it was queued for later, or it
immediately handed off to a flow that was parked waiting for it — in
which case the caller (see
worker::deliver) is responsible for feeding the value back into that flow’s VM and re-enqueuing it asReady. - Flow
Outcome - Terminal outcome of a flow, delivered to whoever holds its
super::handle::FlowHandle. - Flow
State - Where a flow currently sits in its lifecycle.
- Restart
Policy - Restart policy consulted by a
super::supervisor::Supervisorwhen a supervised flow terminates. - Runtime
Error - Scheduler / host infrastructure error — not a bytecode flow fault.
- Send
Error - Why
Runtime::sendcould not deliver a hop. - Spawn
Error - User-facing spawn / load errors (category A in the taxonomy above).
Constants§
- DEFAULT_
QUANTUM - Default instruction budget per scheduling turn (design notes §10).
Chosen as a middle ground: large enough that the per-yield bookkeeping
cost is amortized over meaningful work, small enough that a
pathological
loop {}in one flow can’t visibly stall the others — at 10k simple instructions/turn and even a conservative tens-of-millions of instructions/sec per core, worst-case added latency for a sibling flow is sub-millisecond.
Functions§
- fault_
count - How many
report_faultcalls have been made (tests / diagnostics). - flow_
id_ from_ u64 - A convenience Pid constructor for embedders that stored a raw
u64(e.g. round-tripped throughValue::Pid) and need aFlowIdto call APIs that take one. - next_
flow_ id - report_
fault - Record an infrastructure fault (stderr + counter). Does not panic.