Struct mycelium_kernel::rt::JoinHandle
source · pub struct JoinHandle<T> { /* private fields */ }
Expand description
An owned permission to join a task (await its termination).
This is equivalent to the standard library’s std::thread::JoinHandle
type, but for asynchronous tasks rather than OS threads.
A JoinHandle
detaches the associated task when it is dropped, which
means that there is no longer any handle to the task and no way to await
its termination.
JoinHandle
s implement Future
, so a task’s output can be awaited by
.await
ing its JoinHandle
.
This struct
is returned by the Scheduler::spawn
and
Scheduler::spawn_allocated
methods, and the task::Builder::spawn
and
task::Builder::spawn_allocated
methods.
Implementations§
source§impl<T> JoinHandle<T>
impl<T> JoinHandle<T>
sourcepub fn task_ref(&self) -> TaskRef
pub fn task_ref(&self) -> TaskRef
Returns a TaskRef
referencing the task this JoinHandle
is
associated with.
This increases the task’s reference count; its storage is not
deallocated until all such TaskRef
s are dropped.
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()
.
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).
Trait Implementations§
source§impl<T> Debug for JoinHandle<T>
impl<T> Debug for JoinHandle<T>
source§impl<T> Drop for JoinHandle<T>
impl<T> Drop for JoinHandle<T>
source§impl<T> Future for JoinHandle<T>
impl<T> Future for JoinHandle<T>
source§impl<T> PartialEq<&TaskId> for JoinHandle<T>
impl<T> PartialEq<&TaskId> for JoinHandle<T>
source§impl<T> PartialEq<&TaskRef> for JoinHandle<T>
impl<T> PartialEq<&TaskRef> for JoinHandle<T>
source§impl<T> PartialEq<TaskId> for JoinHandle<T>
impl<T> PartialEq<TaskId> for JoinHandle<T>
source§impl<T> PartialEq<TaskRef> for JoinHandle<T>
impl<T> PartialEq<TaskRef> for JoinHandle<T>
source§impl<T> PartialEq for JoinHandle<T>where
T: PartialEq,
impl<T> PartialEq for JoinHandle<T>where
T: PartialEq,
source§fn eq(&self, other: &JoinHandle<T>) -> bool
fn eq(&self, other: &JoinHandle<T>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<T> Eq for JoinHandle<T>where
T: Eq,
impl<T> StructuralEq for JoinHandle<T>
impl<T> StructuralPartialEq for JoinHandle<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for JoinHandle<T>
impl<T> Send for JoinHandle<T>
impl<T> Sync for JoinHandle<T>
impl<T> Unpin for JoinHandle<T>
impl<T> !UnwindSafe for JoinHandle<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
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.