Fix prod builds (#912)

move AbortOnDrop
This commit is contained in:
Brendan Allan
2023-06-05 23:06:56 +02:00
committed by GitHub
parent 5e89935dcc
commit 73144faa30
4 changed files with 44 additions and 40 deletions

View File

@@ -6,7 +6,7 @@ use crate::{
LocationError, LocationUpdateArgs,
},
prisma::{file_path, indexer_rule, indexer_rules_in_location, location, object, tag},
util::debug_initializer::AbortOnDrop,
util::AbortOnDrop,
};
use rspc::{self, alpha::AlphaRouter, ErrorCode};

View File

@@ -0,0 +1,39 @@
use futures::{pin_mut, Future, Stream};
pub struct AbortOnDrop<T>(pub tokio::task::JoinHandle<T>);
impl<T> Drop for AbortOnDrop<T> {
fn drop(&mut self) {
self.0.abort()
}
}
impl<T> Future for AbortOnDrop<T> {
type Output = Result<T, tokio::task::JoinError>;
fn poll(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
let handle = &mut self.0;
pin_mut!(handle);
handle.poll(cx)
}
}
impl<T> Stream for AbortOnDrop<T> {
type Item = ();
fn poll_next(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
let handle = &mut self.0;
pin_mut!(handle);
handle.poll(cx).map(|_| None)
}
}

View File

@@ -13,8 +13,8 @@ use crate::{
delete_location, scan_location, LocationCreateArgs, LocationError, LocationManagerError,
},
prisma::location,
util::AbortOnDrop,
};
use futures::{pin_mut, Future, Stream};
use prisma_client_rust::QueryError;
use serde::Deserialize;
use thiserror::Error;
@@ -182,41 +182,3 @@ impl InitConfig {
Ok(())
}
}
pub struct AbortOnDrop<T>(pub tokio::task::JoinHandle<T>);
impl<T> Drop for AbortOnDrop<T> {
fn drop(&mut self) {
self.0.abort()
}
}
impl<T> Future for AbortOnDrop<T> {
type Output = Result<T, tokio::task::JoinError>;
fn poll(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
let handle = &mut self.0;
pin_mut!(handle);
handle.poll(cx)
}
}
impl<T> Stream for AbortOnDrop<T> {
type Item = ();
fn poll_next(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
let handle = &mut self.0;
pin_mut!(handle);
handle.poll(cx).map(|_| None)
}
}

View File

@@ -1,6 +1,9 @@
mod abort_on_drop;
pub mod db;
#[cfg(debug_assertions)]
pub mod debug_initializer;
pub mod error;
pub mod migrator;
pub mod seeder;
pub use abort_on_drop::*;