Skip to content

Commit

Permalink
JoinSet docs removes erroneous mentions of .await
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdsk committed Aug 27, 2024
1 parent 7abbab5 commit 8291c15
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions tokio/src/task/join_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ use crate::util::IdleNotifiedSet;
///
/// All of the tasks must have the same return type `T`.
///
/// 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
/// When the `JoinSet` is dropped, all *async* tasks in the `JoinSet` are
/// immediately aborted. Tasks spawned with [`spawn_blocking`] or
/// [`spawn_blocking_on`] can not be aborted as they are not *async*, see [task
/// cancellation].
///
/// # Examples
///
Expand Down Expand Up @@ -54,6 +54,9 @@ use crate::util::IdleNotifiedSet;
/// }
/// }
/// ```
/// [`spawn_blocking`]: fn@Self::spawn_blocking
/// [`spawn_blocking_on`]: fn@Self::spawn_blocking_on
/// [task cancellation]: crate::task#cancellation
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
pub struct JoinSet<T> {
inner: IdleNotifiedSet<JoinHandle<T>>,
Expand Down Expand Up @@ -208,7 +211,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.
/// Note that this task can not be aborted as its not *async*,
/// see [task cancellation].
///
/// # Examples
///
Expand Down Expand Up @@ -242,6 +246,7 @@ impl<T: 'static> JoinSet<T> {
/// This method panics if called outside of a Tokio runtime.
///
/// [`AbortHandle`]: crate::task::AbortHandle
/// [task cancellation]: crate::task#cancellation
#[track_caller]
pub fn spawn_blocking<F>(&mut self, f: F) -> AbortHandle
where
Expand All @@ -256,7 +261,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.
/// Note that this task can not be aborted as its not *async*,
/// see [task cancellation].
///
/// [`AbortHandle`]: crate::task::AbortHandle
#[track_caller]
Expand Down Expand Up @@ -374,12 +380,15 @@ 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).
/// Note that tasks spawned with [`spawn_blocking`] or [`spawn_blocking_on`]
/// can not be aborted as they are not *async*, see [task cancellation].
/// They may cause the call to shutdown to block.
///
/// [`abort_all`]: fn@Self::abort_all
/// [`join_next`]: fn@Self::join_next
/// [`spawn_blocking`]: fn@Self::spawn_blocking
/// [`spawn_blocking_on`]: fn@Self::spawn_blocking_on
/// [task cancellation]: crate::task#cancellation
pub async fn shutdown(&mut self) {
self.abort_all();
while self.join_next().await.is_some() {}
Expand Down Expand Up @@ -463,9 +472,13 @@ 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).
/// Note that tasks spawned with [`spawn_blocking`] or [`spawn_blocking_on`]
/// can not be aborted as they are not *async*, see [task cancellation].
/// They may cause the call to shutdown to block.
///
/// [`spawn_blocking`]: fn@Self::spawn_blocking
/// [`spawn_blocking_on`]: fn@Self::spawn_blocking_on
/// [task cancellation]: crate::task#cancellation
pub fn abort_all(&mut self) {
self.inner.for_each(|jh| jh.abort());
}
Expand Down

0 comments on commit 8291c15

Please sign in to comment.