Attempting to explain as slowly as possible what actually happens when the compiler finds an async
function containing awaits
: it writes a poll
method for you to create something that implements Future
. The generated poll
method polls the Future
s you asked to await
, in order. The interesting bit is that this generated thing that implements Future
and has a poll
method needs to own the things it refers to, which is what leads to some of the most confusing error messages you see when writing this kind of code.
Links:
- Exercises: https://artificialworlds.net/presentations/rust-101/exercises/E-async-web/mod.html
- Slides: https://artificialworlds.net/presentations/rust-101/E-async-web
Rust 101 is a series of videos explaining how to write programs in Rust. The course materials for this series are developed by tweede golf. You can find more information at https://github.com/tweedegolf/101-rs and you can sponsor the work at https://github.com/sponsors/tweedegolf . They are released under the Creative Commons Attribution Share Alike 4.0 International license.
This series of videos is copyright 2024 Andy Balaam and the tweede golf contributors and is released under the Creative Commons Attribution Share Alike 4.0 International license.