use std::ops::{Deref, DerefMut};
use tokio::task::JoinHandle;
#[derive(Debug)]
pub struct AbortOnDropHandle<R>(pub JoinHandle<R>);
impl<R> Drop for AbortOnDropHandle<R> {
fn drop(&mut self) {
self.0.abort();
}
}
impl<R> From<JoinHandle<R>> for AbortOnDropHandle<R> {
fn from(jh: JoinHandle<R>) -> Self {
Self(jh)
}
}
impl<R> Deref for AbortOnDropHandle<R> {
type Target = JoinHandle<R>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<R> DerefMut for AbortOnDropHandle<R> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}