pub struct TaskRef(/* private fields */);
Expand description
A type-erased, reference-counted pointer to a spawned Task
.
Once a task has been spawned, it is generally referenced by a TaskRef
.
When a spawned task is placed in a scheduler’s run queue, dequeuing the next
task will yield a TaskRef
, and a TaskRef
may be converted into a
Waker
or used to await a spawned task’s completion.
TaskRef
s are reference-counted, and the task will be deallocated when the
last TaskRef
pointing to it is dropped.
Implementations§
source§impl TaskRef
impl TaskRef
sourcepub fn id(&self) -> TaskId
pub fn id(&self) -> TaskId
Returns a TaskId
that uniquely identifies this task.
The returned ID does not increment the task’s reference count, and may persist even after the task it identifies has completed and been deallocated.
sourcepub fn cancel(&self) -> bool
pub fn cancel(&self) -> bool
Forcibly cancel the task.
Canceling a task sets a flag indicating that it has been canceled and
should terminate. The next time a canceled task is polled by the
scheduler, it will terminate instead of polling the inner Future
. If
the task has a JoinHandle
, that JoinHandle
will complete with a
JoinError
. The task then will be deallocated once all
JoinHandle
s and TaskRef
s referencing it have been dropped.
This method returns true
if the task was canceled successfully, and
false
if the task could not be canceled (i.e., it has already completed,
has already been canceled, cancel culture has gone TOO FAR, et cetera).
sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns true
if this task has completed.
Tasks are considered completed when the spawned Future
has returned
Poll::Ready
, or if the task has been canceled by the cancel()
method.
Note: This method can return false
after cancel()
has
been called. This is because calling cancel
begins the process of
cancelling a task. The task is not considered canceled until it has been
polled by the scheduler after calling cancel()
.
Trait Implementations§
source§impl<T> PartialEq<&JoinHandle<T>> for TaskRef
impl<T> PartialEq<&JoinHandle<T>> for TaskRef
source§impl<T> PartialEq<&TaskRef> for JoinHandle<T>
impl<T> PartialEq<&TaskRef> for JoinHandle<T>
source§impl<T> PartialEq<JoinHandle<T>> for TaskRef
impl<T> PartialEq<JoinHandle<T>> for TaskRef
source§impl<T> PartialEq<TaskRef> for JoinHandle<T>
impl<T> PartialEq<TaskRef> for JoinHandle<T>
impl Eq for TaskRef
impl Send for TaskRef
impl StructuralPartialEq for TaskRef
impl Sync for TaskRef
Auto Trait Implementations§
impl Freeze for TaskRef
impl !RefUnwindSafe for TaskRef
impl Unpin for TaskRef
impl !UnwindSafe for TaskRef
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)