polars_utils/async_utils/
tokio_handle_ext.rs

1use std::future::Future;
2use std::pin::Pin;
3use std::task::{Context, Poll};
4
5/// Calls [`tokio::task::JoinHandle::abort`] on the join handle when dropped.
6pub struct AbortOnDropHandle<T>(pub tokio::task::JoinHandle<T>);
7
8impl<T> Future for AbortOnDropHandle<T> {
9    type Output = Result<T, tokio::task::JoinError>;
10
11    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
12        Pin::new(&mut self.0).poll(cx)
13    }
14}
15
16impl<T> Drop for AbortOnDropHandle<T> {
17    fn drop(&mut self) {
18        self.0.abort();
19    }
20}