mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
task: stabilize the LocalSet::id() (#7776)
Signed-off-by: ADD-SP <[email protected]>
This commit is contained in:
+19
-25
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user