Ergonomic wrapper for `runtime.spawn_blocking(f).await`. If `f` panics, it will be bubbled up to the calling task.
(runtime: &Handle, f: F)
| 5 | /// |
| 6 | /// If `f` panics, it will be bubbled up to the calling task. |
| 7 | pub async fn asyncify<F, R>(runtime: &Handle, f: F) -> R |
| 8 | where |
| 9 | F: FnOnce() -> R + Send + 'static, |
| 10 | R: Send + 'static, |
| 11 | { |
| 12 | // Ensure that `f` executes in the current span context. |
| 13 | // If there is no current span, or it is disabled, `span` is disabled. |
| 14 | let span = Span::current(); |
| 15 | runtime |
| 16 | .spawn_blocking(move || { |
| 17 | let _enter = span.enter(); |
| 18 | f() |
| 19 | }) |
| 20 | .await |
| 21 | } |
no test coverage detected
searching dependent graphs…