pub fn current_task() -> Option<CurrentTask>Expand description
The task running right now, if any.
Null outside a task, which is what makes it useful: a Rust closure handed to
.task { } or to detached can tell whether Swift’s scheduler is what
called it, and can ask that task whether it has been cancelled — which is the
whole of structured cancellation from this side.
let v = views::task(
&views::text("loading"),
0,
views::TaskPriority::Utility,
file!(),
line!() as i64,
|| {
while !runtime::current_task().is_some_and(|t| t.is_cancelled()) {
// …work…
break;
}
},
);