pub struct AsyncHandle<T> { /* private fields */ }Expand description
A handle to a cancellable async operation
AsyncHandle allows you to:
- Cancel long-running operations cooperatively
- Check if an operation is still running
- Wait for completion with
.await - Abort forcefully if needed
The handle automatically cancels the operation when dropped.
Implementations§
Source§impl<T> AsyncHandle<T>
impl<T> AsyncHandle<T>
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Cancel the operation
This sends a cancellation signal to the async task. The task must cooperatively check for cancellation to actually stop.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if the operation is cancelled
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the operation is still running
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Check if the operation has finished
Sourcepub fn abort(&self)
pub fn abort(&self)
Abort the task immediately
This is more forceful than cancel() - it immediately aborts the task without waiting for cooperative cancellation.
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub fn cancellation_token(&self) -> &CancellationToken
Get the cancellation token for cooperative cancellation
This can be cloned and passed to child tasks for hierarchical cancellation.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for AsyncHandle<T>
impl<T> RefUnwindSafe for AsyncHandle<T>
impl<T> Send for AsyncHandle<T>where
T: Send,
impl<T> Sync for AsyncHandle<T>where
T: Send,
impl<T> Unpin for AsyncHandle<T>
impl<T> UnwindSafe for AsyncHandle<T>
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> Inspectable for T
impl<T> Inspectable for T
Source§fn inspect_if(self, condition: bool, label: &str) -> Selfwhere
Self: Debug,
fn inspect_if(self, condition: bool, label: &str) -> Selfwhere
Self: Debug,
Conditionally inspect this value
Source§fn inspect_with<F>(self, label: &str, f: F) -> Self
fn inspect_with<F>(self, label: &str, f: F) -> Self
Inspect with a custom formatter