pub struct Stage<'s, 'p> { /* private fields */ }Expand description
One active sequential stage, borrowing its plan until result handoff.
Pass &stage as the operation’s Pulse, then use
crate::ResultExt::finish_phase or Complete::complete before ?.
Completion consumes the handle and updates its plan. Dropping it without
completion records Outcome::Abandoned and resolves pending work as
Outcome::NotRun. Shared views have no completion rights.
A second stage cannot begin while the first is live:
use how_far::{prelude::*, NoPulse, PhaseSpec, Stages, Total};
let (mut stages, [a, b]) = Stages::define(&NoPulse, [
PhaseSpec::new("a", 1, Total::Unknown),
PhaseSpec::new("b", 1, Total::Unknown),
]);
let first = stages.begin(a);
let second = stages.begin(b);
first.complete(Ok::<_, how_far::StopReason>(())).unwrap();Implementations§
Source§impl Stage<'_, '_>
impl Stage<'_, '_>
Sourcepub fn fork<const N: usize>(&self, parts: [PhaseSpec<'_>; N]) -> [Child<'_>; N]
pub fn fork<const N: usize>(&self, parts: [PhaseSpec<'_>; N]) -> [Child<'_>; N]
Start independently owned branches within this stage.
This declares Execution::ForkJoin and starts each branch; it does
not schedule work. Move the handles into scoped threads, Rayon work,
or borrowed async futures. Each branch can use different data and
return a different type, or declare a nested Stages sequence.
Hand each result to its branch, join all workers, then hand the
combined result to this stage. A failed branch does not automatically
cancel its siblings. Every returned branch is active: dropping one
unfinished records Outcome::Abandoned, not optional skipped work.
Rejected plans retain cancellation in every branch and record an issue.
The parent cannot be completed while a branch still borrows it:
use how_far::{prelude::*, NoPulse, PhaseSpec, Stages, Total, Outcome};
let (mut stages, [work]) = Stages::define(&NoPulse, [
PhaseSpec::new("work", 1, Total::Unknown),
]);
let work = stages.begin(work);
let [branch] = work.fork([PhaseSpec::new("branch", 1, Total::Unknown)]);
work.complete_as(Outcome::Succeeded);
branch.complete_as(Outcome::Succeeded);Trait Implementations§
Source§impl Complete for Stage<'_, '_>
impl Complete for Stage<'_, '_>
Source§fn complete_as(self, outcome: Outcome)
fn complete_as(self, outcome: Outcome)
Source§fn complete<T, E>(self, result: Result<T, E>) -> Result<T, E>where
E: AsStopReason,
fn complete<T, E>(self, result: Result<T, E>) -> Result<T, E>where
E: AsStopReason,
AsStopReason, record completion, and return the
original result. Read moreSource§fn complete_classified<T, E>(
self,
result: Result<T, E>,
is_stop: impl FnOnce(&E) -> bool,
) -> Result<T, E>
fn complete_classified<T, E>( self, result: Result<T, E>, is_stop: impl FnOnce(&E) -> bool, ) -> Result<T, E>
AsStopReason.Source§fn complete_with<T, E>(
self,
body: impl FnOnce(&mut Self) -> Result<T, E>,
) -> Result<T, E>where
E: AsStopReason,
fn complete_with<T, E>(
self,
body: impl FnOnce(&mut Self) -> Result<T, E>,
) -> Result<T, E>where
E: AsStopReason,
body with this owner, then complete the owner with
the body’s result and return that result unchanged. Read moreSource§fn complete_with_classified<T, E>(
self,
is_stop: impl FnOnce(&E) -> bool,
body: impl FnOnce(&mut Self) -> Result<T, E>,
) -> Result<T, E>
fn complete_with_classified<T, E>( self, is_stop: impl FnOnce(&E) -> bool, body: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<T, E>
complete_with with an explicit classifier, for
a foreign error type that cannot implement AsStopReason, such as an error
wrapped with its source location.