byteflow/scheduler/handle.rs
1use super::oneshot;
2use super::process::{FlowId, FlowOutcome};
3
4/// A reference to a spawned **flow**, returned by
5/// [`super::runtime::Runtime::spawn`].
6///
7/// Holding a `FlowHandle` does not keep the flow alive — it is a way to
8/// (a) read its [`FlowId`] for addressing with `Send`, and (b) block the
9/// *calling native thread* until it finishes via [`FlowHandle::join`].
10/// Dropping without joining is fine (fire-and-forget).
11pub struct FlowHandle {
12 pub(crate) id: FlowId,
13 pub(crate) receiver: oneshot::Receiver<FlowOutcome>,
14}
15
16impl FlowHandle {
17 pub fn id(&self) -> FlowId {
18 self.id
19 }
20
21 /// Block the current (native) thread until the flow terminates.
22 /// **Never call from inside a worker / from bytecode.**
23 pub fn join(self) -> FlowOutcome {
24 match self.receiver.join() {
25 Ok(outcome) => outcome,
26 Err(e) => FlowOutcome::Failed(e.to_string()),
27 }
28 }
29}