From 3ef4097ceb1162f46bb2aac324155a4a7ef324a6 Mon Sep 17 00:00:00 2001 From: asonix Date: Tue, 12 Dec 2023 16:23:02 -0600 Subject: [PATCH] Enable building without tokio_unstable --- .cargo/config | 2 -- .cargo/config.toml | 2 ++ src/sync.rs | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) delete mode 100644 .cargo/config create mode 100644 .cargo/config.toml diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index ba416f7..0000000 --- a/.cargo/config +++ /dev/null @@ -1,2 +0,0 @@ -[build] -rustflags = ["--cfg", "tokio_unstable", "--cfg", "uuid_unstable"] diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..bff29e6 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +rustflags = ["--cfg", "tokio_unstable"] diff --git a/src/sync.rs b/src/sync.rs index 3c5ce28..e79a13d 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -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