Skip to main content
Version: 0.12.x

Async Programming

Async programming in Rust is a recent development, only having been stabilized in Rust 1.39. The async ecosystem is rapidly evolving, and SeaORM is one of the first crates built from the ground up with async support in mind.

The first thing to learn is the Future trait. It's a placeholder for a function that will compute and return some value in the future. It's lazy, meaning .await must be called for any actual work to be done. Future allows us to achieve concurrency with little programming effort, e.g. future::join_all to execute multiple queries in parallel.

Second, async in Rust is multi-threaded programming with syntactic sugar. A Future may move between threads, so any variables used in async bodies must be able to travel between threads, i.e. Send.

Third, there are multiple async runtimes in Rust. async-std and tokio are the two most widely used. SeaORM's underlying driver, SQLx, supports both.

Knowing these concepts is essential to get you up and running in async Rust.