2025-04-11 17:27:56 +08:00
|
|
|
use std::future::Future;
|
|
|
|
|
use tauri::{async_runtime, async_runtime::JoinHandle};
|
|
|
|
|
|
|
|
|
|
pub struct AsyncHandler;
|
|
|
|
|
|
|
|
|
|
impl AsyncHandler {
|
|
|
|
|
pub fn spawn<F, Fut>(f: F) -> JoinHandle<()>
|
|
|
|
|
where
|
|
|
|
|
F: FnOnce() -> Fut + Send + 'static,
|
|
|
|
|
Fut: Future<Output = ()> + Send + 'static,
|
|
|
|
|
{
|
|
|
|
|
async_runtime::spawn(f())
|
|
|
|
|
}
|
2025-08-22 03:52:30 +08:00
|
|
|
|
|
|
|
|
pub fn spawn_blocking<T, F>(f: F) -> JoinHandle<T>
|
|
|
|
|
where
|
|
|
|
|
F: FnOnce() -> T + Send + 'static,
|
|
|
|
|
T: Send + 'static,
|
|
|
|
|
{
|
|
|
|
|
async_runtime::spawn_blocking(f)
|
|
|
|
|
}
|
2025-04-11 17:27:56 +08:00
|
|
|
}
|