A Future
is a suspended computation unit which must be driven to completion by polling it. Hence, when a Future
value is ignored, it is not polled to completion, leading to any errors that might occur at the time of Future
computation execution not being handled.
This can lead to unexpected behaviour if the program assumes that the code in Future
would run.
async fn foo() -> u32 {
get_count().await
}
fn main() {
let _ = foo(); // bad
_ = foo(); // bad
}
async fn foo() -> u32 {
get_count().await
}
fn main() {
let _ = foo().await; // fine
_ = foo().await; // fine
let x = foo(); // fine
}