mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 11:22:04 +00:00
feat(async_runtime): enable track_caller attribute for async_runtime under tracing feature
This commit is contained in:
parent
06374a902a
commit
72be786b86
5
.changes/feat-async_runtime-track.md
Normal file
5
.changes/feat-async_runtime-track.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": feat
|
||||
---
|
||||
|
||||
Enable track_caller attribute for async_runtime under the tracing feature to provide better location information in logs and panics.
|
||||
@ -42,6 +42,7 @@ impl GlobalRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
|
||||
where
|
||||
F: Future + Send + 'static,
|
||||
@ -54,6 +55,7 @@ impl GlobalRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
|
||||
where
|
||||
F: FnOnce() -> R + Send + 'static,
|
||||
@ -66,6 +68,7 @@ impl GlobalRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
fn block_on<F: Future>(&self, task: F) -> F::Output {
|
||||
if let Some(r) = &self.runtime {
|
||||
r.block_on(task)
|
||||
@ -95,6 +98,7 @@ impl Runtime {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
/// Spawns a future onto the runtime.
|
||||
pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
|
||||
where
|
||||
@ -109,6 +113,7 @@ impl Runtime {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
/// Runs the provided function on an executor dedicated to blocking operations.
|
||||
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
|
||||
where
|
||||
@ -120,6 +125,7 @@ impl Runtime {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
/// Runs a future to completion on runtime.
|
||||
pub fn block_on<F: Future>(&self, task: F) -> F::Output {
|
||||
match self {
|
||||
@ -177,6 +183,7 @@ impl RuntimeHandle {
|
||||
h
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
/// Runs the provided function on an executor dedicated to blocking operations.
|
||||
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
|
||||
where
|
||||
@ -188,6 +195,7 @@ impl RuntimeHandle {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
/// Spawns a future onto the runtime.
|
||||
pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
|
||||
where
|
||||
@ -202,6 +210,7 @@ impl RuntimeHandle {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
/// Runs a future to completion on runtime.
|
||||
pub fn block_on<F: Future>(&self, task: F) -> F::Output {
|
||||
match self {
|
||||
@ -258,12 +267,14 @@ pub fn handle() -> RuntimeHandle {
|
||||
runtime.handle()
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
/// Runs a future to completion on runtime.
|
||||
pub fn block_on<F: Future>(task: F) -> F::Output {
|
||||
let runtime = RUNTIME.get_or_init(default_runtime);
|
||||
runtime.block_on(task)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
/// Spawns a future onto the runtime.
|
||||
pub fn spawn<F>(task: F) -> JoinHandle<F::Output>
|
||||
where
|
||||
@ -274,6 +285,7 @@ where
|
||||
runtime.spawn(task)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
/// Runs the provided function on an executor dedicated to blocking operations.
|
||||
pub fn spawn_blocking<F, R>(func: F) -> JoinHandle<R>
|
||||
where
|
||||
@ -284,6 +296,7 @@ where
|
||||
runtime.spawn_blocking(func)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", track_caller)]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn safe_block_on<F>(task: F) -> F::Output
|
||||
where
|
||||
|
||||
Loading…
Reference in New Issue
Block a user