pub fn try_current() -> Option<Task>Available on crate features
alloc and default only.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!"),
}