Rename lib to binstalk (#361)

This commit is contained in:
Félix Saparelli 2022-09-10 18:44:18 +12:00 committed by GitHub
parent a94d83f0d5
commit e25aa50ec9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 25 additions and 25 deletions

View file

@ -0,0 +1,61 @@
use std::{
future::Future,
ops::{Deref, DerefMut},
pin::Pin,
task::{Context, Poll},
};
use tokio::task::JoinHandle;
use crate::errors::BinstallError;
#[derive(Debug)]
pub struct AutoAbortJoinHandle<T>(JoinHandle<T>);
impl<T> AutoAbortJoinHandle<T> {
pub fn new(handle: JoinHandle<T>) -> Self {
Self(handle)
}
}
impl<T> AutoAbortJoinHandle<T>
where
T: Send + 'static,
{
pub fn spawn<F>(future: F) -> Self
where
F: Future<Output = T> + Send + 'static,
{
Self(tokio::spawn(future))
}
}
impl<T> Drop for AutoAbortJoinHandle<T> {
fn drop(&mut self) {
self.0.abort();
}
}
impl<T> Deref for AutoAbortJoinHandle<T> {
type Target = JoinHandle<T>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> DerefMut for AutoAbortJoinHandle<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<T> Future for AutoAbortJoinHandle<T> {
type Output = Result<T, BinstallError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Pin::new(&mut Pin::into_inner(self).0)
.poll(cx)
.map(|res| res.map_err(BinstallError::TaskJoinError))
}
}