pub struct FlowHandle { /* private fields */ }Expand description
A reference to a spawned flow, returned by
super::runtime::Runtime::spawn.
Holding a FlowHandle does not keep the flow alive — it is a way to
(a) read its FlowId for addressing with Send, and (b) block the
calling native thread until it finishes via FlowHandle::join.
Dropping without joining is fine (fire-and-forget).
Implementations§
Source§impl FlowHandle
impl FlowHandle
pub fn id(&self) -> FlowId
Sourcepub fn join(self) -> FlowOutcome
pub fn join(self) -> FlowOutcome
Block the current (native) thread until the flow terminates.
Never call from inside a worker / from a native invoked by bytecode.
That case is machine-checked: this returns
FlowOutcome::Failed with JoinError::CalledFromWorker rather
than deadlocking the pool.
Returns FlowOutcome::Failed rather than blocking forever if the
flow was destroyed without producing an outcome — most commonly
Runtime::shutdown while the flow was suspended, since shutdown does
not drain flows out of the timer or the worker deques. The message
comes from super::error::RuntimeError::Abandoned, so it is
distinguishable from a flow that genuinely faulted.
Sourcepub fn join_checked(self) -> Result<FlowOutcome, JoinError>
pub fn join_checked(self) -> Result<FlowOutcome, JoinError>
Same as Self::join, but surfaces JoinError instead of folding
it into FlowOutcome::Failed.
Sourcepub fn try_join(&self) -> Option<FlowOutcome>
pub fn try_join(&self) -> Option<FlowOutcome>
The outcome if the flow has already terminated, None if it is still
running. Never waits.
For embedders that drive their own loop and cannot surrender a thread
to FlowHandle::join. Takes &self, so it can be polled until it
answers; note that the outcome is handed out exactly once, and a
further poll after that reports
super::error::RuntimeError::AlreadyCollected as
FlowOutcome::Failed rather than repeating it.
Sourcepub fn join_timeout(&self, timeout: Duration) -> Option<FlowOutcome>
pub fn join_timeout(&self, timeout: Duration) -> Option<FlowOutcome>
Wait up to timeout for the flow to terminate; None if it is still
running when the bound elapses.
This is the variant to reach for in anything with a deadline — a control loop, a watchdog, a test harness — since it is the only join whose worst-case duration the caller chooses.
Sourcepub fn join_deadline(&self, deadline: Instant) -> Option<FlowOutcome>
pub fn join_deadline(&self, deadline: Instant) -> Option<FlowOutcome>
FlowHandle::join_timeout against an absolute deadline, for callers
that already track one and must not have it drift across repeated
waits.