Enable building without tokio_unstable

This commit is contained in:
asonix 2023-12-12 16:23:02 -06:00
parent 722a02e679
commit 3ef4097ceb
3 changed files with 14 additions and 2 deletions

View file

@ -1,2 +0,0 @@
[build]
rustflags = ["--cfg", "tokio_unstable", "--cfg", "uuid_unstable"]

2
.cargo/config.toml Normal file
View file

@ -0,0 +1,2 @@
[build]
rustflags = ["--cfg", "tokio_unstable"]

View file

@ -46,13 +46,19 @@ where
F: std::future::Future + 'static,
F::Output: 'static,
{
#[cfg(not(tokio_unstable))]
let _ = name;
let span = tracing::trace_span!(parent: None, "spawn task");
let guard = span.enter();
#[cfg(tokio_unstable)]
let handle = tokio::task::Builder::new()
.name(name)
.spawn_local(future)
.expect("Failed to spawn");
#[cfg(not(tokio_unstable))]
let handle = tokio::task::spawn_local(future);
drop(guard);
handle
@ -64,15 +70,21 @@ where
F: FnOnce() -> Out + Send + 'static,
Out: Send + 'static,
{
#[cfg(not(tokio_unstable))]
let _ = name;
let outer_span = tracing::Span::current();
let span = tracing::trace_span!(parent: None, "spawn blocking task");
let guard = span.enter();
#[cfg(tokio_unstable)]
let handle = tokio::task::Builder::new()
.name(name)
.spawn_blocking(move || outer_span.in_scope(function))
.expect("Failed to spawn");
#[cfg(not(tokio_unstable))]
let handle = tokio::task::spawn_blocking(move || outer_span.in_scope(function));
drop(guard);
handle