Function async_std::task::try_current
source · pub fn try_current() -> Option<Task>
Expand description
Returns a handle to the current task if called within the context of a task created by block_on
,
spawn
, or Builder::spawn
, otherwise returns None
.
Examples
use async_std::task;
match task::try_current() {
Some(t) => println!("The name of this task is {:?}", t.name()),
None => println!("Not inside a task!"),
}