use crate::EngineTests;
use ctor::ctor;
use dtor::dtor;
use std::sync::OnceLock;
use tokio::sync::{Mutex, MutexGuard};
pub static ENGINE: OnceLock<Mutex<EngineTests>> = OnceLock::new();
pub async fn engine() -> MutexGuard<'static, EngineTests> {
let mutex = ENGINE.get().expect("engine_config! not called");
let mut engine = mutex.lock().await;
engine.init().await.expect("Failed to initialize engine");
engine
}
#[macro_export]
macro_rules! engine_config {
($($tt:tt)*) => {
#[$crate::ctor::ctor(unsafe)]
#[allow(non_snake_case)]
fn init_engine_globally() {
$crate::base::engines::ENGINE.get_or_init(|| {
$crate::tokio::sync::Mutex::new({ $($tt)* })
});
}
};
}
#[ctor(unsafe)]
fn setup_signal_handler() {
ctrlc::set_handler(move || {
println!("\n\n⚠ Ctrl+C detected — emergency exit.");
println!("Callback on_stop will not be called. Resources may not be released.");
std::process::exit(0);
})
.ok();
}
#[dtor(unsafe)]
fn cleanup() {
if let Some(mutex) = ENGINE.get() {
if let Ok(mut engine) = mutex.try_lock() {
engine.shutdown();
}
}
}