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.
This is idempotent - calling it multiple times has no additional effect.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if this source has been cancelled.
Trait Implementations§
Source§impl Debug for StopSource
impl Debug for StopSource
Source§impl Default for StopSource
impl Default for StopSource
Auto Trait Implementations§
impl !Freeze for StopSource
impl RefUnwindSafe for StopSource
impl Send for StopSource
impl Sync for StopSource
impl Unpin 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> StopExt for Twhere
T: Stop,
impl<T> StopExt for Twhere
T: Stop,
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