pub struct LaneControl<'a> { /* private fields */ }Expand description
A cancellation capability shared by a coordinator and its lanes.
The executor creates one control per run and lends it to the coordinator and to every lane, so cancellation is visible in both directions: a coordinator that stops feeding work cancels the lanes, and an executor that observes a lane failure cancels the coordinator. Cancellation is a request: already running callback code is not stopped.
An adapter bridges its own cancellation state into the control it observes
and must treat LaneControl::cancelled as a request to stop feeding work.
A backend whose own executor can stop a run without reaching a lane callback
(a failed child-session entry, for example) lends the side that waits on
cancellation a LaneControl::with_probe view of the same control, so that
wait also observes the backend’s stop signal.
§Example
use hataori::LaneControl;
let control = LaneControl::new();
assert!(!control.cancelled());
control.cancel();
assert!(control.cancelled());A probe view shares the same cancellation flag and adds an external signal:
use hataori::LaneControl;
use std::sync::atomic::{AtomicBool, Ordering};
let control = LaneControl::new();
let backend_stopped = AtomicBool::new(false);
let probe = || backend_stopped.load(Ordering::Acquire);
let probed = control.with_probe(&probe);
assert!(!probed.cancelled());
backend_stopped.store(true, Ordering::Release);
assert!(probed.cancelled());
assert!(!control.cancelled(), "the probe is not an own-flag cancellation");
probed.cancel();
assert!(control.cancelled(), "views share one cancellation flag");Implementations§
Source§impl LaneControl<'static>
impl LaneControl<'static>
Source§impl<'a> LaneControl<'a>
impl<'a> LaneControl<'a>
Sourcepub fn with_probe(&'a self, probe: &'a (dyn Fn() -> bool + Sync)) -> Self
pub fn with_probe(&'a self, probe: &'a (dyn Fn() -> bool + Sync)) -> Self
Returns a view of this control that also reports probe as cancelled.
The view shares this control’s cancellation flag, so a lane and a
coordinator cannot diverge on an ordinary cancel; the probe only adds a
stop signal the executor owns. LaneControl::cancelled is evaluated as
own flag first and then the probe, so a probe must be cheap and
non-blocking.
Trait Implementations§
Source§impl Debug for LaneControl<'_>
impl Debug for LaneControl<'_>
Auto Trait Implementations§
impl<'a> !Freeze for LaneControl<'a>
impl<'a> !RefUnwindSafe for LaneControl<'a>
impl<'a> !UnwindSafe for LaneControl<'a>
impl<'a> Send for LaneControl<'a>
impl<'a> Sync for LaneControl<'a>
impl<'a> Unpin for LaneControl<'a>
impl<'a> UnsafeUnpin for LaneControl<'a>
Blanket Implementations§
§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
§impl<T> ConvUtil for T
impl<T> ConvUtil for T
§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more