pub struct StopSource { /* private fields */ }Expand description
A stack-based cancellation source.
This is a zero-allocation cancellation primitive. The source owns the
atomic and can issue borrowed references via as_ref().
§Example
use almost_enough::{StopSource, Stop};
let source = StopSource::new();
let stop = source.as_ref();
// Check in your operation
assert!(!stop.should_stop());
// Cancel when needed
source.cancel();
assert!(stop.should_stop());§Const Construction
StopSource can be created in const context:
use almost_enough::StopSource;
static GLOBAL_STOP: StopSource = StopSource::new();Implementations§
Source§impl StopSource
impl StopSource
Sourcepub const fn cancelled() -> Self
pub const fn cancelled() -> Self
Create a source that is already cancelled.
Useful for testing or when you want to signal immediate stop.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Signal all references to stop.
A Release swap: writes made before a cancel() are visible to a
thread whose is_cancelled returns true after
it, even when several threads cancel. On targets without atomic swap
(thumbv6m, say) it is a Release store, which guarantees that only
for a single canceller. Calling it again changes nothing else.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for StopSource
impl RefUnwindSafe for StopSource
impl Send for StopSource
impl Sync for StopSource
impl Unpin for StopSource
impl UnsafeUnpin for StopSource
impl UnwindSafe for StopSource
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> DebouncedTimeoutExt for Twhere
T: Stop,
impl<T> DebouncedTimeoutExt for Twhere
T: Stop,
Source§fn with_debounced_timeout(self, duration: Duration) -> DebouncedTimeout<Self>
fn with_debounced_timeout(self, duration: Duration) -> DebouncedTimeout<Self>
Add a debounced timeout to this stop. Read more
Source§fn with_debounced_deadline(self, deadline: Instant) -> DebouncedTimeout<Self>
fn with_debounced_deadline(self, deadline: Instant) -> DebouncedTimeout<Self>
Add a debounced timeout with an absolute deadline.
Source§impl<T> StopExt for Twhere
T: Stop,
impl<T> StopExt for Twhere
T: Stop,
Source§fn or<S: Stop>(self, other: S) -> OrStop<Self, S>
fn or<S: Stop>(self, other: S) -> OrStop<Self, S>
Combine this stop with another, stopping if either stops. Read more
Source§fn into_boxed(self) -> BoxedStopwhere
Self: 'static,
fn into_boxed(self) -> BoxedStopwhere
Self: 'static,
👎Deprecated since 0.4.5:
use into_token(), whose StopToken checks the same way and is Clone
Convert this stop into a
BoxedStop. Deprecated: use
into_token(), whose StopToken checks the
same way and is Clone.Source§fn into_token(self) -> StopTokenwhere
Self: 'static,
fn into_token(self) -> StopTokenwhere
Self: 'static,
Source§impl<T> TimeoutExt for Twhere
T: Stop,
impl<T> TimeoutExt for Twhere
T: Stop,
Source§fn with_timeout(self, duration: Duration) -> WithTimeout<Self>
fn with_timeout(self, duration: Duration) -> WithTimeout<Self>
Add a timeout to this stop. Read more
Source§fn with_deadline(self, deadline: Instant) -> WithTimeout<Self>
fn with_deadline(self, deadline: Instant) -> WithTimeout<Self>
Add an absolute deadline to this stop. Read more