File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,18 @@ use std::{fmt, num::NonZeroU64};
55/// An opaque ID that uniquely identifies a task relative to all other currently
66/// running tasks.
77///
8+ /// A task's ID may be re-used for another task only once *both* of the
9+ /// following happen:
10+ /// 1. The task itself exits.
11+ /// 2. The task's [`JoinHandle`](crate::task::JoinHandle) is either dropped, or
12+ /// joined on (for example, by `await`ing it to completion).
13+ ///
814/// # Notes
915///
10- /// - Task IDs are unique relative to other *currently running* tasks. When a
11- /// task completes, the same ID may be used for another task.
1216/// - Task IDs are *not* sequential, and do not indicate the order in which
1317/// tasks are spawned, what runtime a task is spawned on, or any other data.
18+ /// - Holding an [`AbortHandle`](crate::task::AbortHandle) alone does not
19+ /// prevent a completed task's ID from being re-used.
1420/// - The task ID of the currently running task can be obtained from inside the
1521/// task via the [`task::try_id()`](crate::task::try_id()) and
1622/// [`task::id()`](crate::task::id()) functions and from outside the task via
Original file line number Diff line number Diff line change @@ -295,7 +295,7 @@ impl<T: 'static> JoinSet<T> {
295295 ///
296296 /// This method is cancel safe. If `join_next_with_id` is used as the event in a `tokio::select!`
297297 /// statement and some other branch completes first, it is guaranteed that no tasks were
298- /// removed from this `JoinSet`.
298+ /// removed from this `JoinSet`, nor any task's ID freed for re-use by another task .
299299 ///
300300 /// [task ID]: crate::task::Id
301301 /// [`JoinError::id`]: fn@crate::task::JoinError::id
@@ -535,7 +535,9 @@ impl<T: 'static> JoinSet<T> {
535535 /// * `Poll::Ready(None)` if the `JoinSet` is empty.
536536 ///
537537 /// Note that this method may return `Poll::Pending` even if one of the tasks has completed.
538- /// This can happen if the [coop budget] is reached.
538+ /// This can happen if the [coop budget] is reached. However, the task's `JoinHandle` is only
539+ /// consumed (and the task ID freed for potential re-use) if this method returns
540+ /// `Poll::Ready(Some(_))`.
539541 ///
540542 /// [coop budget]: crate::task::coop#cooperative-scheduling
541543 /// [task ID]: crate::task::Id
You can’t perform that action at this time.
0 commit comments