mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-02-20 07:37:26 -05:00
@@ -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};
|
||||
|
||||
39
core/src/util/abort_on_drop.rs
Normal file
39
core/src/util/abort_on_drop.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
Reference in New Issue
Block a user