Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/feat-async_runtime-track.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": minor:feat
---

Enable track_caller attribute for async_runtime under the tracing feature to provide better location information in logs and panics.
13 changes: 13 additions & 0 deletions crates/tauri/src/async_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl GlobalRuntime {
}
}

#[cfg_attr(feature = "tracing", track_caller)]
Comment thread
Legend-Master marked this conversation as resolved.
Resolved
fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading