diff --git a/tokio-util/Cargo.toml b/tokio-util/Cargo.toml index d215590d9f2..d444bdf6b81 100644 --- a/tokio-util/Cargo.toml +++ b/tokio-util/Cargo.toml @@ -21,7 +21,7 @@ categories = ["asynchronous"] default = [] # Shorthand for enabling everything -full = ["codec", "compat", "io-util", "time", "net", "rt"] +full = ["codec", "compat", "io-util", "time", "net", "rt", "join-map"] net = ["tokio/net"] compat = ["futures-io",] @@ -29,7 +29,8 @@ codec = [] time = ["tokio/time","slab"] io = [] io-util = ["io", "tokio/rt", "tokio/io-util"] -rt = ["tokio/rt", "tokio/sync", "futures-util", "hashbrown"] +rt = ["tokio/rt", "tokio/sync", "futures-util"] +join-map = ["rt", "hashbrown"] __docs_rs = ["futures-util"] @@ -43,8 +44,6 @@ futures-util = { version = "0.3.0", optional = true } pin-project-lite = "0.2.11" slab = { version = "0.4.4", optional = true } # Backs `DelayQueue` tracing = { version = "0.1.29", default-features = false, features = ["std"], optional = true } - -[target.'cfg(tokio_unstable)'.dependencies] hashbrown = { version = "0.14.0", default-features = false, optional = true } [dev-dependencies] diff --git a/tokio-util/src/cfg.rs b/tokio-util/src/cfg.rs index 4035255aff0..7f3df063b3e 100644 --- a/tokio-util/src/cfg.rs +++ b/tokio-util/src/cfg.rs @@ -69,3 +69,14 @@ macro_rules! cfg_time { )* } } + +#[cfg(feature = "rt")] +macro_rules! cfg_join_map { + ($($item:item)*) => { + $( + #[cfg(feature = "join-map")] + #[cfg_attr(docsrs, doc(cfg(feature = "join-map")))] + $item + )* + } +} diff --git a/tokio-util/src/task/join_map.rs b/tokio-util/src/task/join_map.rs index 13e27bb670b..af3177c3c5e 100644 --- a/tokio-util/src/task/join_map.rs +++ b/tokio-util/src/task/join_map.rs @@ -29,10 +29,6 @@ use tokio::task::{AbortHandle, Id, JoinError, JoinSet, LocalSet}; /// /// When the `JoinMap` is dropped, all tasks in the `JoinMap` are immediately aborted. /// -/// **Note**: This type depends on Tokio's [unstable API][unstable]. See [the -/// documentation on unstable features][unstable] for details on how to enable -/// Tokio's unstable features. -/// /// # Examples /// /// Spawn multiple tasks and wait for them: @@ -96,11 +92,9 @@ use tokio::task::{AbortHandle, Id, JoinError, JoinSet, LocalSet}; /// ``` /// /// [`JoinSet`]: tokio::task::JoinSet -/// [unstable]: tokio#unstable-features /// [abort]: fn@Self::abort /// [abort_matching]: fn@Self::abort_matching /// [contains]: fn@Self::contains_key -#[cfg_attr(docsrs, doc(cfg(all(feature = "rt", tokio_unstable))))] pub struct JoinMap { /// A map of the [`AbortHandle`]s of the tasks spawned on this `JoinMap`, /// indexed by their keys and task IDs. diff --git a/tokio-util/src/task/mod.rs b/tokio-util/src/task/mod.rs index 6d0c379fe20..a4dd0931b93 100644 --- a/tokio-util/src/task/mod.rs +++ b/tokio-util/src/task/mod.rs @@ -1,13 +1,12 @@ //! Extra utilities for spawning tasks -#[cfg(tokio_unstable)] -mod join_map; mod spawn_pinned; pub use spawn_pinned::LocalPoolHandle; -#[cfg(tokio_unstable)] -#[cfg_attr(docsrs, doc(cfg(all(tokio_unstable, feature = "rt"))))] -pub use join_map::{JoinMap, JoinMapKeys}; +cfg_join_map! { + mod join_map; + pub use join_map::{JoinMap, JoinMapKeys}; +} pub mod task_tracker; pub use task_tracker::TaskTracker; diff --git a/tokio-util/tests/task_join_map.rs b/tokio-util/tests/task_join_map.rs index 8757f8b5c6e..513b1725b63 100644 --- a/tokio-util/tests/task_join_map.rs +++ b/tokio-util/tests/task_join_map.rs @@ -1,6 +1,6 @@ #![allow(unknown_lints, unexpected_cfgs)] #![warn(rust_2018_idioms)] -#![cfg(all(feature = "rt", tokio_unstable))] +#![cfg(feature = "join-map")] use tokio::sync::oneshot; use tokio::time::Duration; @@ -25,7 +25,7 @@ async fn test_with_sleep() { map.detach_all(); assert_eq!(map.len(), 0); - assert!(matches!(map.join_next().await, None)); + assert!(map.join_next().await.is_none()); for i in 0..10 { map.spawn(i, async move { @@ -44,7 +44,7 @@ async fn test_with_sleep() { for was_seen in &seen { assert!(was_seen); } - assert!(matches!(map.join_next().await, None)); + assert!(map.join_next().await.is_none()); // Do it again. for i in 0..10 { @@ -63,7 +63,7 @@ async fn test_with_sleep() { for was_seen in &seen { assert!(was_seen); } - assert!(matches!(map.join_next().await, None)); + assert!(map.join_next().await.is_none()); } #[tokio::test]