pub struct TaskHandle(/* private fields */);Expand description
A non-owning handle used to cancel a spawned task manually.
Dropping this handle does not cancel the task. Call TaskHandle::cancel
explicitly, or use TaskHandle::owned when the task should be cancelled as
its owner is dropped.
Implementations§
Source§impl TaskHandle
impl TaskHandle
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Cancel the task.
Use it when an event or state change makes an in-progress task no longer
necessary. This method must run within Freya’s current context, use
TaskHandle::try_cancel for cleanup that may run outside it.
Sourcepub fn try_cancel(&self)
pub fn try_cancel(&self)
Try to cancel the task if Freya’s current context is available.
Unlike TaskHandle::cancel, this does nothing when called outside
Freya’s context. Prefer it in destructors and other cleanup paths where a
context might no longer exist.
Sourcepub fn owned(self) -> OwnedTaskHandle
pub fn owned(self) -> OwnedTaskHandle
Upgrade to an OwnedTaskHandle that cancels the task when its last
clone is dropped.
Retain the returned handle for as long as the task should run. Useful for a task owned by another long-lived value rather than by a component scope:
struct Worker {
_task: OwnedTaskHandle,
}
let worker = Worker {
_task: spawn_forever(forward_messages()).owned(),
};Trait Implementations§
Source§impl Clone for TaskHandle
impl Clone for TaskHandle
Source§fn clone(&self) -> TaskHandle
fn clone(&self) -> TaskHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for TaskHandle
Source§impl Debug for TaskHandle
impl Debug for TaskHandle
impl Eq for TaskHandle
Source§impl From<TaskId> for TaskHandle
impl From<TaskId> for TaskHandle
Source§fn from(value: TaskId) -> TaskHandle
fn from(value: TaskId) -> TaskHandle
Source§impl Hash for TaskHandle
impl Hash for TaskHandle
Source§impl PartialEq for TaskHandle
impl PartialEq for TaskHandle
impl StructuralPartialEq for TaskHandle
Auto Trait Implementations§
impl Freeze for TaskHandle
impl RefUnwindSafe for TaskHandle
impl Send for TaskHandle
impl Sync for TaskHandle
impl Unpin for TaskHandle
impl UnsafeUnpin for TaskHandle
impl UnwindSafe for TaskHandle
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§impl<T> ComponentProps for T
impl<T> ComponentProps for T
fn changed(&self, other: &(dyn ComponentProps + 'static)) -> bool
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more