pub struct TaskGuard { /* private fields */ }Expand description
RAII owner for a spawned tokio task.
Dropping the guard aborts the task. Await or release the handle with
Self::disarm when the task must outlive the current scope.
Implementations§
Source§impl TaskGuard
impl TaskGuard
Sourcepub fn new(handle: JoinHandle<()>) -> Self
pub fn new(handle: JoinHandle<()>) -> Self
Own a spawned task with a default label.
Sourcepub fn with_label(handle: JoinHandle<()>, label: &'static str) -> Self
pub fn with_label(handle: JoinHandle<()>, label: &'static str) -> Self
Own a spawned task with a static label used for debugging.
Sourcepub fn disarm(&mut self) -> Option<JoinHandle<()>>
pub fn disarm(&mut self) -> Option<JoinHandle<()>>
Release the handle without aborting, for documented-detached handoff.
Returns None only if the guard was already disarmed.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether the owned task has finished.
Returns false once the guard is disarmed (no handle held), since the
task is no longer owned by this guard.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TaskGuard
impl RefUnwindSafe for TaskGuard
impl Send for TaskGuard
impl Sync for TaskGuard
impl Unpin for TaskGuard
impl UnsafeUnpin for TaskGuard
impl UnwindSafe for TaskGuard
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