task: stabilize the LocalSet::id() (#7776)

Signed-off-by: ADD-SP <[email protected]>
This commit is contained in:
Qi
2025-12-16 19:02:09 +08:00
committed by GitHub
parent 0fa7755e97
commit 231a3a69f9
+19 -25
View File
@@ -1,7 +1,6 @@
//! Runs `!Send` futures on the current thread.
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::{Arc, Mutex};
#[cfg(tokio_unstable)]
use crate::runtime;
use crate::runtime::task::{
self, JoinHandle, LocalOwnedTasks, SpawnLocation, Task, TaskHarnessScheduleHooks,
@@ -844,6 +843,25 @@ impl LocalSet {
Err(_access_error) => (f.take().unwrap())(),
}
}
/// Returns the [`Id`] of the current [`LocalSet`] runtime.
///
/// # Examples
///
/// ```rust
/// use tokio::task;
///
/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() {
/// let local_set = task::LocalSet::new();
/// println!("Local set id: {}", local_set.id());
/// # }
/// ```
///
/// [`Id`]: struct@crate::runtime::Id
pub fn id(&self) -> runtime::Id {
runtime::Id::new(self.context.shared.local_state.owned.id)
}
}
cfg_unstable! {
@@ -914,30 +932,6 @@ cfg_unstable! {
.unhandled_panic = behavior;
self
}
/// Returns the [`Id`] of the current `LocalSet` runtime.
///
/// # Examples
///
/// ```rust
/// use tokio::task;
///
/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() {
/// let local_set = task::LocalSet::new();
/// println!("Local set id: {}", local_set.id());
/// # }
/// ```
///
/// **Note**: This is an [unstable API][unstable]. The public API of this type
/// may break in 1.x releases. See [the documentation on unstable
/// features][unstable] for details.
///
/// [unstable]: crate#unstable-features
/// [`Id`]: struct@crate::runtime::Id
pub fn id(&self) -> runtime::Id {
runtime::Id::new(self.context.shared.local_state.owned.id)
}
}
}