@@ -5,16 +5,28 @@ 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. There is no active [`JoinHandle`] associated with this task.
12+ ///
13+ /// A [`JoinHandle`] is considered active in the following situations:
14+ /// - You are explicitly holding a [`JoinHandle`], [`AbortHandle`], or
15+ /// `tokio_util::task::AbortOnDropHandle`.
16+ /// - The task is being tracked by a [`JoinSet`] or `tokio_util::task::JoinMap`.
17+ ///
818/// # Notes
919///
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.
1220/// - Task IDs are *not* sequential, and do not indicate the order in which
1321/// tasks are spawned, what runtime a task is spawned on, or any other data.
1422/// - The task ID of the currently running task can be obtained from inside the
1523/// task via the [`task::try_id()`](crate::task::try_id()) and
1624/// [`task::id()`](crate::task::id()) functions and from outside the task via
1725/// the [`JoinHandle::id()`](crate::task::JoinHandle::id()) function.
26+ ///
27+ /// [`JoinHandle`]: crate::task::JoinHandle
28+ /// [`AbortHandle`]: crate::task::AbortHandle
29+ /// [`JoinSet`]: crate::task::JoinSet
1830#[ cfg_attr( docsrs, doc( cfg( all( feature = "rt" ) ) ) ) ]
1931#[ derive( Clone , Copy , Debug , Hash , Eq , PartialEq , PartialOrd , Ord ) ]
2032pub struct Id ( pub ( crate ) NonZeroU64 ) ;
0 commit comments