Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tokio_util): Stabilise JoinMap #7075

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions tokio-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I'll have to think about what implications this has for our MSRV.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hashbrown 0.14.0 has a rust-version = "1.64.0".
hashbrown 0.15.2 has a rust-version = "1.65.0".

It doesn't seem to have an explicit MSRV policy, but it is inline with tokio-util's 1.70.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this, but I don't want to require hashbrown if you're just using the TaskTracker. Can you add a join_map feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable. Will do


[dev-dependencies]
Expand Down
7 changes: 1 addition & 6 deletions tokio-util/src/task/join_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -96,11 +92,10 @@ 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))))]
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
pub struct JoinMap<K, V, S = RandomState> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you add the join_map feature, this annotation may not be necessary. Please try removing it and checking the docs.

/// A map of the [`AbortHandle`]s of the tasks spawned on this `JoinMap`,
/// indexed by their keys and task IDs.
Expand Down
5 changes: 1 addition & 4 deletions tokio-util/src/task/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
//! 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"))))]
mod join_map;
pub use join_map::{JoinMap, JoinMapKeys};

pub mod task_tracker;
Expand Down
8 changes: 4 additions & 4 deletions tokio-util/tests/task_join_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unknown_lints, unexpected_cfgs)]
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "rt", tokio_unstable))]
#![cfg(feature = "rt")]

use tokio::sync::oneshot;
use tokio::time::Duration;
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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]
Expand Down
Loading