use crate::runtime::AbortHandle;
use crate::runtime::AbortHandleRef;
pub(crate) struct TaskAbortHandle<T> {
task: Option<async_executor::Task<T>>,
}
impl<T: 'static + Send> TaskAbortHandle<T> {
pub(crate) fn new_handle(task: async_executor::Task<T>) -> AbortHandleRef {
Box::new(Self { task: Some(task) })
}
}
impl<T: Send> AbortHandle for TaskAbortHandle<T> {
fn abort(mut self: Box<Self>) {
drop(self.task.take());
}
}
impl<T> Drop for TaskAbortHandle<T> {
fn drop(&mut self) {
if let Some(task) = self.task.take() {
task.detach()
}
}
}