Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-stream/src/utils/task_handles_ext.rs
6939 views
1
use std::future::Future;
2
use std::pin::Pin;
3
use std::task::{Context, Poll};
4
5
/// Calls [`tokio::task::JoinHandle::abort`] on the join handle when dropped.
6
pub struct AbortOnDropHandle<T>(pub tokio::task::JoinHandle<T>);
7
8
impl<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
16
impl<T> Drop for AbortOnDropHandle<T> {
17
fn drop(&mut self) {
18
self.0.abort();
19
}
20
}
21
22