Files
100-exercises-to-learn-rust/book/src/08_futures/08_outro.md
Luca Palmieri 99591a715e Formatter (#51)
Enforce consistent formatting use `dprint`
2024-05-24 17:00:03 +02:00

1.8 KiB
Raw Blame History

Outro

Rusts asynchronous model is quite powerful, but it does introduce additional complexity. Take time to know your tools: dive deep into tokios documentation and get familiar with its primitives to make the most out of it.

Keep in mind, as well, that there is ongoing work at the language and std level to streamline and “complete” Rusts asynchronous story. You may experience some rough edges in your day-to-day work due to some of these missing pieces.

A few recommendations for a mostly-pain-free async experience:

  • Pick a runtime and stick to it.
    Some primitives (e.g. timers, I/O) are not portable across runtimes. Trying to mix runtimes is likely to cause you pain. Trying to write code thats runtime agnostic can significantly increase the complexity of your codebase. Avoid it if you can.
  • There is no stable Stream/AsyncIterator interface yet.
    An AsyncIterator is, conceptually, an iterator that yields new items asynchronously. There is ongoing design work, but no consensus (yet). If youre using tokio, refer to tokio_stream as your go-to interface.
  • Be careful with buffering.
    It is often the cause of subtle bugs. Check out “Barbara battles buffered streams” for more details.
  • There is no equivalent of scoped threads for asynchronous tasks.
    Check out “The scoped task trilemma” for more details.

Dont let these caveats scare you: asynchronous Rust is being used effectively at massive scale (e.g. AWS, Meta) to power foundational services.
You will have to master it if youre planning building networked applications in Rust.