pub struct ChildStopper { /* private fields */ }Expand description
A cancellation primitive with tree-structured parent-child relationships.
ChildStopper uses a unified clone model: clone to share, any clone can cancel.
When cancelled, it does NOT affect its parent or siblings - only this node
and any of its children.
§Example
use almost_enough::{ChildStopper, Stop};
let parent = ChildStopper::new();
let child = parent.child();
// Clone to share across threads
let child_clone = child.clone();
// Any clone can cancel
child_clone.cancel();
assert!(child.should_stop());
// Parent is not affected
assert!(!parent.should_stop());§Performance
- Size: 8 bytes (one pointer)
check(): ~5-20ns depending on tree depth (walks parent chain)- Root nodes: no parent check, similar to
Stopper
Implementations§
Source§impl ChildStopper
impl ChildStopper
Sourcepub fn with_parent<T: Stop + 'static>(parent: T) -> Self
pub fn with_parent<T: Stop + 'static>(parent: T) -> Self
Create a new tree node with a parent.
The child will stop if either:
cancel()is called on this node (or any clone)- Any ancestor in the parent chain is cancelled
§Example
use almost_enough::{Stopper, ChildStopper, Stop};
let root = Stopper::new();
let child = ChildStopper::with_parent(root.clone());
root.cancel();
assert!(child.should_stop());Sourcepub fn child(&self) -> ChildStopper
pub fn child(&self) -> ChildStopper
Create a child of this tree node.
The child will stop if either this node or any ancestor is cancelled. Cancelling the child does NOT affect this node.
§Example
use almost_enough::{ChildStopper, Stop};
let parent = ChildStopper::new();
let child = parent.child();
let grandchild = child.child();
child.cancel();
assert!(!parent.should_stop()); // Parent unaffected
assert!(child.should_stop());
assert!(grandchild.should_stop()); // Inherits from parentSourcepub fn cancel(&self)
pub fn cancel(&self)
Cancel this node (and all its children).
This does NOT affect the parent or siblings.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if this node is cancelled (either directly or via ancestor).
Trait Implementations§
Source§impl Cancellable for ChildStopper
impl Cancellable for ChildStopper
Source§impl Clone for ChildStopper
impl Clone for ChildStopper
Source§fn clone(&self) -> ChildStopper
fn clone(&self) -> ChildStopper
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChildStopper
impl Debug for ChildStopper
Source§impl Default for ChildStopper
impl Default for ChildStopper
Auto Trait Implementations§
impl Freeze for ChildStopper
impl !RefUnwindSafe for ChildStopper
impl Send for ChildStopper
impl Sync for ChildStopper
impl Unpin for ChildStopper
impl !UnwindSafe for ChildStopper
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