Files
clash-verge-rev-lite/src-tauri/src/process/async_handler.rs
Tunglies 251678493c edition 2024 (#4702)
* feat: update Cargo.toml for 2024 edition and optimize release profiles

* feat: refactor environment variable settings for Linux and improve code organization

* Refactor conditional statements to use `&&` for improved readability

- Updated multiple files to combine nested `if let` statements using `&&` for better clarity and conciseness.
- This change enhances the readability of the code by reducing indentation levels and making the conditions more straightforward.
- Affected files include: media_unlock_checker.rs, profile.rs, clash.rs, profiles.rs, async_proxy_query.rs, core.rs, handle.rs, hotkey.rs, service.rs, timer.rs, tray/mod.rs, merge.rs, seq.rs, config.rs, proxy.rs, window.rs, general.rs, dirs.rs, i18n.rs, init.rs, network.rs, and window.rs in the resolve module.

* refactor: streamline conditional checks using `&&` for improved readability

* fix: update release profile settings for panic behavior and optimization

* fix: adjust optimization level in Cargo.toml and reorder imports in lightweight.rs
2025-09-10 09:49:06 +08:00

85 lines
3.0 KiB
Rust

#[cfg(feature = "tokio-trace")]
use std::any::type_name;
use std::future::Future;
#[cfg(feature = "tokio-trace")]
use std::panic::Location;
use tauri::{async_runtime, async_runtime::JoinHandle};
pub struct AsyncHandler;
impl AsyncHandler {
pub fn handle() -> async_runtime::RuntimeHandle {
async_runtime::handle()
}
#[track_caller]
pub fn spawn<F, Fut>(f: F) -> JoinHandle<()>
where
F: FnOnce() -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send + 'static,
{
#[cfg(feature = "tokio-trace")]
Self::log_task_info(&f);
async_runtime::spawn(f())
}
#[track_caller]
pub fn spawn_blocking<T, F>(f: F) -> JoinHandle<T>
where
F: FnOnce() -> T + Send + 'static,
T: Send + 'static,
{
#[cfg(feature = "tokio-trace")]
Self::log_task_info(&f);
async_runtime::spawn_blocking(f)
}
#[allow(dead_code)]
#[track_caller]
pub fn block_on<Fut>(fut: Fut) -> Fut::Output
where
Fut: Future + Send + 'static,
{
#[cfg(feature = "tokio-trace")]
Self::log_task_info(&fut);
async_runtime::block_on(fut)
}
#[cfg(feature = "tokio-trace")]
#[track_caller]
fn log_task_info<F>(f: &F)
where
F: ?Sized,
{
const TRACE_SPECIAL_SIZE: [usize; 3] = [0, 4, 24];
let size = std::mem::size_of_val(f);
if TRACE_SPECIAL_SIZE.contains(&size) {
return;
}
let location = Location::caller();
let type_str = type_name::<F>();
let size_str = format!("{} bytes", size);
let loc_str = format!(
"{}:{}:{}",
location.file(),
location.line(),
location.column()
);
println!(
"┌────────────────────┬─────────────────────────────────────────────────────────────────────────────┐"
);
println!("{:<18}{:<80}", "Field", "Value");
println!(
"├────────────────────┼─────────────────────────────────────────────────────────────────────────────┤"
);
println!("{:<18}{:<80}", "Type of task", type_str);
println!("{:<18}{:<80}", "Size of task", size_str);
println!("{:<18}{:<80}", "Called from", loc_str);
println!(
"└────────────────────┴─────────────────────────────────────────────────────────────────────────────┘"
);
}
}