fix non-tracing spawn

This commit is contained in:
Christien Rioux 2024-08-01 20:27:54 -05:00
parent 6eac54bbc9
commit 9005e0718e

View File

@ -54,8 +54,10 @@ cfg_if! {
cfg_if! { cfg_if! {
if #[cfg(feature="rt-async-std")] { if #[cfg(feature="rt-async-std")] {
MustJoinHandle::new(async_std::task::Builder::new().name(name.to_string()).spawn(future).unwrap()) MustJoinHandle::new(async_std::task::Builder::new().name(name.to_string()).spawn(future).unwrap())
} else if #[cfg(feature="rt-tokio")] { } else if #[cfg(all(feature="rt-tokio", feature="tracing"))] {
MustJoinHandle::new(tokio::task::Builder::new().name(name).spawn(future).unwrap()) MustJoinHandle::new(tokio::task::Builder::new().name(name).spawn(future).unwrap())
} else if #[cfg(feature="rt-tokio")] {
MustJoinHandle::new(tokio::task::spawn(future))
} }
} }
} }
@ -67,8 +69,10 @@ cfg_if! {
cfg_if! { cfg_if! {
if #[cfg(feature="rt-async-std")] { if #[cfg(feature="rt-async-std")] {
MustJoinHandle::new(async_std::task::Builder::new().name(name.to_string()).local(future).unwrap()) MustJoinHandle::new(async_std::task::Builder::new().name(name.to_string()).local(future).unwrap())
} else if #[cfg(feature="rt-tokio")] { } else if #[cfg(all(feature="rt-tokio", feature="tracing"))] {
MustJoinHandle::new(tokio::task::Builder::new().name(name).spawn_local(future).unwrap()) MustJoinHandle::new(tokio::task::Builder::new().name(name).spawn_local(future).unwrap())
} else if #[cfg(feature="rt-tokio")] {
MustJoinHandle::new(tokio::task::spawn_local(future))
} }
} }
} }
@ -80,8 +84,10 @@ cfg_if! {
cfg_if! { cfg_if! {
if #[cfg(feature="rt-async-std")] { if #[cfg(feature="rt-async-std")] {
drop(async_std::task::Builder::new().name(name.to_string()).spawn(future).unwrap()); drop(async_std::task::Builder::new().name(name.to_string()).spawn(future).unwrap());
} else if #[cfg(feature="rt-tokio")] { } else if #[cfg(all(feature="rt-tokio", feature="tracing"))] {
drop(tokio::task::Builder::new().name(name).spawn(future).unwrap()); drop(tokio::task::Builder::new().name(name).spawn(future).unwrap());
} else if #[cfg(feature="rt-tokio")] {
drop(tokio::task::spawn(future))
} }
} }
} }
@ -93,8 +99,10 @@ cfg_if! {
cfg_if! { cfg_if! {
if #[cfg(feature="rt-async-std")] { if #[cfg(feature="rt-async-std")] {
drop(async_std::task::Builder::new().name(name.to_string()).local(future).unwrap()); drop(async_std::task::Builder::new().name(name.to_string()).local(future).unwrap());
} else if #[cfg(feature="rt-tokio")] { } else if #[cfg(all(feature="rt-tokio", feature="tracing"))] {
drop(tokio::task::Builder::new().name(name).spawn_local(future).unwrap()); drop(tokio::task::Builder::new().name(name).spawn_local(future).unwrap());
} else if #[cfg(feature="rt-tokio")] {
drop(tokio::task::spawn_local(future))
} }
} }
} }
@ -111,8 +119,10 @@ cfg_if! {
let _name = name; let _name = name;
// async_std::task::Builder blocking doesn't work like spawn_blocking() // async_std::task::Builder blocking doesn't work like spawn_blocking()
async_std::task::spawn_blocking(blocking_task).await async_std::task::spawn_blocking(blocking_task).await
} else if #[cfg(feature="rt-tokio")] { } else if #[cfg(all(feature="rt-tokio", feature="tracing"))] {
tokio::task::Builder::new().name(name).spawn_blocking(blocking_task).unwrap().await.unwrap_or(err_result) tokio::task::Builder::new().name(name).spawn_blocking(blocking_task).unwrap().await.unwrap_or(err_result)
} else if #[cfg(feature="rt-tokio")] {
tokio::task::spawn_blocking(blocking_task).await.unwrap_or(err_result)
} else { } else {
#[compile_error("must use an executor")] #[compile_error("must use an executor")]
} }