diff --git a/core/src/api/locations.rs b/core/src/api/locations.rs index 99736d4c2..de0f80352 100644 --- a/core/src/api/locations.rs +++ b/core/src/api/locations.rs @@ -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}; diff --git a/core/src/util/abort_on_drop.rs b/core/src/util/abort_on_drop.rs new file mode 100644 index 000000000..f001405f3 --- /dev/null +++ b/core/src/util/abort_on_drop.rs @@ -0,0 +1,39 @@ +use futures::{pin_mut, Future, Stream}; + +pub struct AbortOnDrop(pub tokio::task::JoinHandle); + +impl Drop for AbortOnDrop { + fn drop(&mut self) { + self.0.abort() + } +} + +impl Future for AbortOnDrop { + type Output = Result; + + fn poll( + mut self: std::pin::Pin<&mut Self>, + cx: &mut std::task::Context<'_>, + ) -> std::task::Poll { + let handle = &mut self.0; + + pin_mut!(handle); + + handle.poll(cx) + } +} + +impl Stream for AbortOnDrop { + type Item = (); + + fn poll_next( + mut self: std::pin::Pin<&mut Self>, + cx: &mut std::task::Context<'_>, + ) -> std::task::Poll> { + let handle = &mut self.0; + + pin_mut!(handle); + + handle.poll(cx).map(|_| None) + } +} diff --git a/core/src/util/debug_initializer.rs b/core/src/util/debug_initializer.rs index 0f3639f84..2c01f246e 100644 --- a/core/src/util/debug_initializer.rs +++ b/core/src/util/debug_initializer.rs @@ -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(pub tokio::task::JoinHandle); - -impl Drop for AbortOnDrop { - fn drop(&mut self) { - self.0.abort() - } -} - -impl Future for AbortOnDrop { - type Output = Result; - - fn poll( - mut self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> std::task::Poll { - let handle = &mut self.0; - - pin_mut!(handle); - - handle.poll(cx) - } -} - -impl Stream for AbortOnDrop { - type Item = (); - - fn poll_next( - mut self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> std::task::Poll> { - let handle = &mut self.0; - - pin_mut!(handle); - - handle.poll(cx).map(|_| None) - } -} diff --git a/core/src/util/mod.rs b/core/src/util/mod.rs index e535dd3b0..d772b5099 100644 --- a/core/src/util/mod.rs +++ b/core/src/util/mod.rs @@ -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::*;