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

sync: add tokio_util::sync::TaskTracker #6033

Merged
merged 27 commits into from
Oct 22, 2023
Merged

sync: add tokio_util::sync::TaskTracker #6033

merged 27 commits into from
Oct 22, 2023

Conversation

Darksonn
Copy link
Contributor

@Darksonn Darksonn commented Sep 23, 2023

On our topic page for graceful shutdown, we currently recommend using the close flag of an mpsc channel to wait for things to shut down. That's pretty terrible. Let's add a dedicated utility for this.

Rendered docs
Closes: #5585

@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync labels Sep 23, 2023
@Darksonn Darksonn added the M-task Module: tokio/task label Sep 23, 2023
tokio-util/src/sync/mod.rs Outdated Show resolved Hide resolved
This was a hack for something I removed.
Comment on lines 280 to 284
pub fn new() -> Self {
Self {
inner: Arc::new(TaskTrackerInner::new()),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A thought I had: I could rename this to new_open and add a new_closed. This might help prevent mistakes where you forget to call close.

@hawkw hawkw self-requested a review September 24, 2023 17:38
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

overall, this looks very nice! we've previously written a somewhat similar utility in the drain crate, which essentially provides a combination TaskTracker and CancellationToken, so it's nice to have this as part of tokio-util.

i commented on a few minor nits and suggestions, but overall it looks great!

tokio-util/src/sync/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/sync/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/sync/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/sync/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/sync/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/sync/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/sync/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/sync/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/sync/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/tests/sync_task_tracker.rs Outdated Show resolved Hide resolved
@Darksonn Darksonn requested a review from hawkw October 1, 2023 20:13
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

Looks good to me! I left a few minor docs suggestions, but I feel good about the implementation overall.

tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Show resolved Hide resolved
@Darksonn
Copy link
Contributor Author

@hawkw Thoughts about the terminology discussed in #6033 (comment)?

@Darksonn Darksonn requested a review from hawkw October 11, 2023 13:59
error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]`
60
   --> tokio-util/src/task/task_tracker.rs:591:5
61
    |
62
591 |     fn clone(&self) -> TaskTrackerToken {
63
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
64
    |
65
Copy link
Member

@davidbarsky davidbarsky left a comment

Choose a reason for hiding this comment

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

take it or leave it, but i removed some usage of the second-person perspective. personally, i prefer to avoid the second-person perspective in rustdocs, but it's your call.

tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
tokio-util/src/task/task_tracker.rs Outdated Show resolved Hide resolved
@Darksonn Darksonn enabled auto-merge (squash) October 22, 2023 14:11
@Darksonn Darksonn merged commit 7041083 into master Oct 22, 2023
70 checks passed
@Darksonn Darksonn deleted the alice/task-tracker branch October 22, 2023 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync M-task Module: tokio/task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Waiting for things to shut down
4 participants