mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-14 12:26:47 +00:00
* Refactor the task module * Fix clippy warning * Simplify task-local entries * Reduce the amount of future wrapping * Cleanup * Simplify stealing
28 lines
687 B
Rust
28 lines
687 B
Rust
use crate::task::Task;
|
|
|
|
/// Returns a handle to the current task.
|
|
///
|
|
/// # Panics
|
|
///
|
|
/// This function will panic if not called within the context of a task created by [`block_on`],
|
|
/// [`spawn`], or [`Builder::spawn`].
|
|
///
|
|
/// [`block_on`]: fn.block_on.html
|
|
/// [`spawn`]: fn.spawn.html
|
|
/// [`Builder::spawn`]: struct.Builder.html#method.spawn
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// # async_std::task::block_on(async {
|
|
/// #
|
|
/// use async_std::task;
|
|
///
|
|
/// println!("The name of this task is {:?}", task::current().name());
|
|
/// #
|
|
/// # })
|
|
/// ```
|
|
pub fn current() -> Task {
|
|
Task::get_current(|t| t.clone())
|
|
.expect("`task::current()` called outside the context of a task")
|
|
}
|