flams_math_archives/utils/
mod.rs

1pub mod errors;
2pub mod ignore_source;
3pub mod lazy_file;
4pub mod path_ext;
5
6pub trait AsyncEngine: 'static {
7    fn background(f: impl FnOnce() + Send + 'static);
8    fn block_on<R: Send + Sync + 'static>(
9        f: impl FnOnce() -> R + Send + Sync + 'static,
10    ) -> impl std::future::Future<Output = R> + Send + Sync;
11    fn exec_after(delay: std::time::Duration, f: impl FnOnce() + Send + 'static);
12}
13
14pub struct SyncEngine;
15
16impl AsyncEngine for SyncEngine {
17    #[inline]
18    fn background(f: impl FnOnce() + Send + 'static) {
19        let _ = std::thread::spawn(f);
20    }
21    fn block_on<R: Send + Sync>(
22        f: impl FnOnce() -> R + Send + Sync,
23    ) -> impl std::future::Future<Output = R> + Send + Sync {
24        std::future::ready(f())
25    }
26    fn exec_after(delay: std::time::Duration, f: impl FnOnce() + Send + 'static) {
27        std::thread::spawn(move || {
28            std::thread::sleep(delay);
29            f();
30        });
31    }
32}