Calling an async fn starts a task. A call whose result is dropped would run unobserved, and
its result and errors would be lost, so it must be awaited, stored or returned.
Wrong#
async fn ping(): int = 1
fn main() {
ping()
print("done")
}Fixed#
async fn ping(): int = 1
fn main() {
let n = await ping()
print(n)
}Common causes#
- Forgetting
awaiton a call made for its side effect. - Starting several tasks: store them, then
await (a, b)orawait tasks.