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

JoinSet, clarify behaviour of blocking code under abort/drop #6802

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion tokio/src/task/join_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use crate::util::IdleNotifiedSet;
///
/// All of the tasks must have the same return type `T`.
///
/// When the `JoinSet` is dropped, all tasks in the `JoinSet` are immediately aborted.
/// When the `JoinSet` is dropped, all non-blocking tasks in the `JoinSet` are
/// immediately aborted. Tasks spawned with
/// [`spawn_blocking`](Self::spawn_blocking) will abort when they reach an
/// `await` point
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't make sense to talk about .await points with spawn_blocking.

You may want to reword these things by referencing the general docs on cancellation of tasks, and by copying the note about spawn_blocking from there into the right spots.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't make sense to talk about .await points with spawn_blocking.

Ahh yeah ofc, I should have taken the time to look at the definition of spawn_blocking 😅.

by copying the note about spawn_blocking from there into the right spots.

Thats perfect!

///
/// # Examples
///
Expand Down Expand Up @@ -205,6 +208,8 @@ impl<T: 'static> JoinSet<T> {
/// it in this `JoinSet`, returning an [`AbortHandle`] that can be
/// used to remotely cancel the task.
///
/// Note that the task can only abort once it reaches an `await` point.
///
/// # Examples
///
/// Spawn multiple blocking tasks and wait for them.
Expand Down Expand Up @@ -251,6 +256,8 @@ impl<T: 'static> JoinSet<T> {
/// provided runtime and store it in this `JoinSet`, returning an
/// [`AbortHandle`] that can be used to remotely cancel the task.
///
/// Note that the task can only abort once it reaches an `await` point.
///
/// [`AbortHandle`]: crate::task::AbortHandle
#[track_caller]
pub fn spawn_blocking_on<F>(&mut self, f: F, handle: &Handle) -> AbortHandle
Expand Down Expand Up @@ -367,6 +374,10 @@ impl<T: 'static> JoinSet<T> {
/// This method ignores any panics in the tasks shutting down. When this call returns, the
/// `JoinSet` will be empty.
///
/// Note that tasks can only abort once they reach an `await` point, this
/// might take a while for tasks containing blocking code even if they are
/// spawned with [`spawn_blocking`](Self::spawn_blocking).
///
/// [`abort_all`]: fn@Self::abort_all
/// [`join_next`]: fn@Self::join_next
pub async fn shutdown(&mut self) {
Expand Down Expand Up @@ -451,6 +462,10 @@ impl<T: 'static> JoinSet<T> {
///
/// This does not remove the tasks from the `JoinSet`. To wait for the tasks to complete
/// cancellation, you should call `join_next` in a loop until the `JoinSet` is empty.
///
/// Note that tasks can only abort once they reach an `await` point, this
/// might take a while for tasks containing blocking code even if they are
/// spawned with [`spawn_blocking`](Self::spawn_blocking).
pub fn abort_all(&mut self) {
self.inner.for_each(|jh| jh.abort());
}
Expand Down
Loading