Skip to content
Merged
Changes from all 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
21 changes: 14 additions & 7 deletions crates/core/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use futures::{Future, FutureExt};
use std::borrow::Cow;
use std::pin::pin;
use tokio::sync::oneshot;
use tracing::Span;

pub mod prometheus_handle;

Expand Down Expand Up @@ -40,13 +41,19 @@ where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
tokio::task::spawn_blocking(f)
.await
.unwrap_or_else(|e| match e.try_into_panic() {
Ok(panic_payload) => std::panic::resume_unwind(panic_payload),
// the only other variant is cancelled, which shouldn't happen because we don't cancel it.
Err(e) => panic!("Unexpected JoinError: {e}"),
})
// Ensure that `f` executes in the current span context.
// If there is no current span, or it is disabled, `span` is disabled.
let span = Span::current();
tokio::task::spawn_blocking(move || {
let _enter = span.enter();
f()
})
.await
.unwrap_or_else(|e| match e.try_into_panic() {
Ok(panic_payload) => std::panic::resume_unwind(panic_payload),
// the only other variant is cancelled, which shouldn't happen because we don't cancel it.
Err(e) => panic!("Unexpected JoinError: {e}"),
})
}

/// Await `fut`, while also polling `also`.
Expand Down
Loading