doc: add a comment in cancel_during_run. (#5267)

Signed-off-by: Tricster <mediosrity@gmail.com>

Signed-off-by: Tricster <mediosrity@gmail.com>
This commit is contained in:
MediosZ
2022-11-18 12:45:05 +08:00
committed by GitHub
parent b6aeaf4fe5
commit 7e4077805b

View File

@@ -269,6 +269,9 @@ async fn cancel_during_run() {
*caller.data_mut() = 1; *caller.data_mut() = 1;
let dtor = SetOnDrop(caller); let dtor = SetOnDrop(caller);
Box::new(async move { Box::new(async move {
// SetOnDrop is not destroyed when dropping the reference of it
// here. Instead, it is moved into the future where it's forced
// to live in and will be destroyed at the end of the future.
drop(&dtor); drop(&dtor);
tokio::task::yield_now().await; tokio::task::yield_now().await;
Ok(()) Ok(())