Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions tokio/src/task/local.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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! {
Expand Down Expand Up @@ -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)
}
}
}

Expand Down