Should clarify the behavior when dropping a Task handle
I think the document can be improved with some clarification
since the unblock()
pub fn unblock<T, F>(f: F) -> Task<T>
where
F: FnOnce() -> T + Send + 'static,
T: Send + 'static,
{
Executor::spawn(async move { f() })
}
where f is not a future,
and the return type Task which re-export the type async_task::Task. While async_task document said
Dropping a Task cancels it, which means its future won’t be polled again. To drop the Task handle without canceling it, use detach() instead. To cancel a task gracefully and wait until it is fully destroyed, use the cancel() method.
Note that canceling a task actually wakes it and reschedules one last time. Then, the executor can destroy the task by simply dropping its Runnable or by invoking run().
It might lead of misunderstanding that a piece of code in thread context can be cancel, but std::thread does not provide this capability.