pub struct Stopper { /* private fields */ }Expand description
A cancellation primitive with unified clone semantics.
This is the recommended default for most use cases. Clone it to share the cancellation state - any clone can cancel or check status.
§Example
use almost_enough::{Stopper, Stop};
let stop = Stopper::new();
// Pass a clone to another thread
let stop2 = stop.clone();
std::thread::spawn(move || {
while !stop2.should_stop() {
// do work
break;
}
}).join().unwrap();
// Cancel from original
stop.cancel();§Performance
- Size: 8 bytes (one pointer)
check(): ~1-2ns (single atomic load with Relaxed ordering)clone(): atomic incrementcancel(): atomic store
Implementations§
Source§impl Stopper
impl Stopper
Sourcepub fn cancelled() -> Self
pub fn cancelled() -> Self
Create a stopper 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 clones 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 cancellation has been requested.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Stopper
impl RefUnwindSafe for Stopper
impl Send for Stopper
impl Sync for Stopper
impl Unpin for Stopper
impl UnwindSafe for Stopper
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<C> StopDropRoll for Cwhere
C: Cancellable,
impl<C> StopDropRoll for Cwhere
C: Cancellable,
Source§fn stop_on_drop(&self) -> CancelGuard<C>
fn stop_on_drop(&self) -> CancelGuard<C>
Create a guard that will stop this source on drop. 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