Originally posted by cynical
View Post
The same is also possible of futures in Rust. See the FutureExt then method in the futures crate.
The problem is that this can often create a deeply nested spaghetti monster if you try to do anything sufficiently complex. In addition to being harder to read and write for a newcomer to async, there are also some patterns which can't be represented safely here, and the generated state machines can get quite complex. Using the async await syntax, this gives the compiler an edge to reduce the generate state machines to much smaller, more efficient structures. It also opens the door to some patterns which previously weren't compatible with the functional approach, without resorting to heap allocations and reference counters. async / await-generated state machines can comfortably work entirely from the stack.
Code:
let scope = async { grab_user_from_db(&username) .await? .get_friends() .await? .get_health_records() .await }; if let Err(why) = scope.await { process_err(why); }
Comment