pub struct AbortHandle { /* private fields */ }
rt
only.Expand description
An owned permission to abort a spawned task, without awaiting its completion.
Unlike a JoinHandle
, an AbortHandle
does not represent the
permission to await the task’s completion, only to terminate it.
The task may be aborted by calling the AbortHandle::abort
method.
Dropping an AbortHandle
releases the permission to terminate the task
— it does not abort the task.
Be aware that tasks spawned using spawn_blocking
cannot be aborted
because they are not async. If you call abort
on a spawn_blocking
task,
then this will not have any effect, and the task will continue running
normally. The exception is if the task has not started running yet; in that
case, calling abort
may prevent the task from starting.
Implementations§
Source§impl AbortHandle
impl AbortHandle
Sourcepub fn abort(&self)
pub fn abort(&self)
Abort the task associated with the handle.
Awaiting a cancelled task might complete as usual if the task was
already completed at the time it was cancelled, but most likely it
will fail with a cancelled JoinError
.
If the task was already cancelled, such as by JoinHandle::abort
,
this method will do nothing.
Be aware that tasks spawned using spawn_blocking
cannot be aborted
because they are not async. If you call abort
on a spawn_blocking
task, then this will not have any effect, and the task will continue
running normally. The exception is if the task has not started running
yet; in that case, calling abort
may prevent the task from starting.
See also the module level docs for more information on cancellation.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Checks if the task associated with this AbortHandle
has finished.
Please note that this method can return false
even if abort
has been
called on the task. This is because the cancellation process may take
some time, and this method does not return true
until it has
completed.
Trait Implementations§
Source§impl Clone for AbortHandle
impl Clone for AbortHandle
Source§impl Debug for AbortHandle
impl Debug for AbortHandle
Source§impl Drop for AbortHandle
impl Drop for AbortHandle
impl RefUnwindSafe for AbortHandle
impl Send for AbortHandle
impl Sync for AbortHandle
impl UnwindSafe for AbortHandle
Auto Trait Implementations§
impl Freeze for AbortHandle
impl Unpin for AbortHandle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes