//! Utility to abort an async task if its logical owner is dropped use tokio::task::JoinHandle; /// When this struct is dropped, the contained task will be aborted #[derive(Debug)] pub struct OwnedHandle { handle: JoinHandle, } impl From> for OwnedHandle { fn from(handle: JoinHandle) -> Self { Self { handle } } } impl Drop for OwnedHandle { fn drop(&mut self) { self.handle.abort(); } }