I'm trying to write a function similar to these
pub fn spawn_blocking_with_tracing<F, R>(f: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
let current_span = tracing::Span::current();
spawn_blocking(move || current_span.in_scope(f))
}
pub fn spawn_with_tracing<F, R>(f: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static + Future<Output = R>,
{
let current_span = tracing::Span::current();
spawn(current_span.in_scope(f))
}
}
}
So that I can spawn_pinned() while maintaining the current span for tracing purposes. I wrote this
use tokio::task::JoinHandle;
pub fn spawn_pinned_with_tracing<F, R>(p: LocalPoolHandle,f: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static + futures::Future<Output=R>,
{
let current_span = tracing::Span::current();
p.spawn_pinned(move || current_span.in_scope(f))
}
But I'm having a hell of a time using it, I keep getting:
error[E0271]: expected `[async block@/celPool/celData/Works/projects/leptos/integrations/axum/src/lib.rs:795:58: 814:18]` to be a future that resolves to `[async block@/celPool/celData/Works/projects/leptos/integrations/axum/src/lib.rs:795:58: 814:18]`, but it resolves to `()`
--> /celPool/celData/Works/projects/leptos/integrations/axum/src/lib.rs:795:17
|
795 | spawn_pinned_with_tracing(local_pool, || async move {
| _________________^^^^^^^^^^^^^^^^^^^^^^^^^________________-
| | |
| | expected `async` block, found `()`
796 | | let app = {
797 | | let full_path = full_path.clone();
798 | | let (req, req_parts) = generate_request_and_parts(req).await;
... |
813 | | forward_stream(&options, res_options2, bundle, runtime, scope, tx).await;
814 | | });
| |_________________- the expected `async` block
|
= note: expected `async` block `[async block@/celPool/celData/Works/projects/leptos/integrations/axum/src/lib.rs:795:58: 814:18]`
found unit type `()`
note: required by a bound in `spawn_pinned_with_tracing`
I'm really not sure what I'm doing wrong here. Is the function return type wrong? Am I misunderstanding how to call it?