Skip to main content

Async Programming in Rust

Async programming in Rust is a recent development, only having been stabilized in Rust 1.39. The async ecosystem is rapidly evolving, and SeaStreamer is an async-only library.

The first concept to learn is the Future trait. Future allows us to achieve concurrency with little programming effort, e.g. future::join_all to execute multiple tasks in parallel.

The second concept to learn is the Stream trait. It's like Iterator, but async. It is very powerful, and allows us to manipulate streams ergonomically by composing Map, Filter and Fold.

Third, there are multiple async runtimes in Rust. async-std and tokio are the two most widely used in production, and SeaStreamer supports both of them. These async runtimes are multi-threaded, meaning that a Future may be moved between threads, but it can only happen at .await points. There is true parallelism - so race condition and contention can and do happen.

Understanding these concepts is essential to get your hands on real-time async programming in Rust.