mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
task: add AbortOnDropHandle::detach (#7400)
This commit is contained in:
@@ -5,6 +5,7 @@ use tokio::task::{AbortHandle, JoinError, JoinHandle};
|
||||
|
||||
use std::{
|
||||
future::Future,
|
||||
mem::ManuallyDrop,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
@@ -46,6 +47,15 @@ impl<T> AbortOnDropHandle<T> {
|
||||
pub fn abort_handle(&self) -> AbortHandle {
|
||||
self.0.abort_handle()
|
||||
}
|
||||
|
||||
/// Cancels aborting on drop and returns the original [`JoinHandle`].
|
||||
pub fn detach(self) -> JoinHandle<T> {
|
||||
// Avoid invoking `AbortOnDropHandle`'s `Drop` impl
|
||||
let this = ManuallyDrop::new(self);
|
||||
// SAFETY: `&this.0` is a reference, so it is certainly initialized, and
|
||||
// it won't be double-dropped because it's in a `ManuallyDrop`
|
||||
unsafe { std::ptr::read(&this.0) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Future for AbortOnDropHandle<T> {
|
||||
|
||||
Reference in New Issue
Block a user