The documentation for the 'cancel' method of the async_global_executor::Task struct includes the statement "Note that canceling a task actually wakes it and reschedules one last time". I interpreted this to mean that, after cancel is called, the task will return from an 'await' one more time, perhaps just because this made sense to me... it would give the task an opportunity to recognize that it had been cancelled and perform cleanup. It's not, however, clear that this is happening. Example code ():
[dependencies]
async-std = "1.12"
async-executor = "1.5.0"
async-global-executor = "2.3"
futures = "0.3.0"
fn main() {
let task1 = async_global_executor::spawn(async {
async_std::task::sleep(std::time::Duration::from_secs(60)).await;
println!("task_one: exiting");
});
let task2 = async_global_executor::spawn(async {
async_std::task::sleep(std::time::Duration::from_secs(60)).await;
println!("task_two: exiting");
});
futures::executor::block_on(async_std::task::sleep(std::time::Duration::from_secs(5)));
futures::executor::block_on(task1.cancel());
futures::executor::block_on(task2.cancel());
}
I expected the print statements to be executed upon cancelation, but they were not. Am I interpreting the documentation completely wrong, or is there something else more subtle going on?