Skip to content

Commit d83d2d9

Browse files
feat(async_runtime): enable track_caller attribute for async_runtime (#14905)
* feat(async_runtime): enable track_caller attribute for async_runtime under tracing feature * fix: `track_caller` enable by default for async_runtime --------- Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com>
1 parent be0e4bd commit d83d2d9

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": minor:feat
3+
---
4+
5+
Enable track_caller attribute for async_runtime to provide better location information in logs and panics.

crates/tauri/src/async_runtime.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl GlobalRuntime {
4242
}
4343
}
4444

45+
#[track_caller]
4546
fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
4647
where
4748
F: Future + Send + 'static,
@@ -54,6 +55,7 @@ impl GlobalRuntime {
5455
}
5556
}
5657

58+
#[track_caller]
5759
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
5860
where
5961
F: FnOnce() -> R + Send + 'static,
@@ -66,6 +68,7 @@ impl GlobalRuntime {
6668
}
6769
}
6870

71+
#[track_caller]
6972
fn block_on<F: Future>(&self, task: F) -> F::Output {
7073
if let Some(r) = &self.runtime {
7174
r.block_on(task)
@@ -95,6 +98,7 @@ impl Runtime {
9598
}
9699
}
97100

101+
#[track_caller]
98102
/// Spawns a future onto the runtime.
99103
pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
100104
where
@@ -109,6 +113,7 @@ impl Runtime {
109113
}
110114
}
111115

116+
#[track_caller]
112117
/// Runs the provided function on an executor dedicated to blocking operations.
113118
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
114119
where
@@ -120,6 +125,7 @@ impl Runtime {
120125
}
121126
}
122127

128+
#[track_caller]
123129
/// Runs a future to completion on runtime.
124130
pub fn block_on<F: Future>(&self, task: F) -> F::Output {
125131
match self {
@@ -177,6 +183,7 @@ impl RuntimeHandle {
177183
h
178184
}
179185

186+
#[track_caller]
180187
/// Runs the provided function on an executor dedicated to blocking operations.
181188
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
182189
where
@@ -188,6 +195,7 @@ impl RuntimeHandle {
188195
}
189196
}
190197

198+
#[track_caller]
191199
/// Spawns a future onto the runtime.
192200
pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
193201
where
@@ -202,6 +210,7 @@ impl RuntimeHandle {
202210
}
203211
}
204212

213+
#[track_caller]
205214
/// Runs a future to completion on runtime.
206215
pub fn block_on<F: Future>(&self, task: F) -> F::Output {
207216
match self {
@@ -258,12 +267,14 @@ pub fn handle() -> RuntimeHandle {
258267
runtime.handle()
259268
}
260269

270+
#[track_caller]
261271
/// Runs a future to completion on runtime.
262272
pub fn block_on<F: Future>(task: F) -> F::Output {
263273
let runtime = RUNTIME.get_or_init(default_runtime);
264274
runtime.block_on(task)
265275
}
266276

277+
#[track_caller]
267278
/// Spawns a future onto the runtime.
268279
pub fn spawn<F>(task: F) -> JoinHandle<F::Output>
269280
where
@@ -274,6 +285,7 @@ where
274285
runtime.spawn(task)
275286
}
276287

288+
#[track_caller]
277289
/// Runs the provided function on an executor dedicated to blocking operations.
278290
pub fn spawn_blocking<F, R>(func: F) -> JoinHandle<R>
279291
where
@@ -284,6 +296,7 @@ where
284296
runtime.spawn_blocking(func)
285297
}
286298

299+
#[track_caller]
287300
#[allow(dead_code)]
288301
pub(crate) fn safe_block_on<F>(task: F) -> F::Output
289302
where

0 commit comments

Comments
 (0)