Skip to main content
Version: 0.4.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 to a function that will compute and return some value in the future. It's lazy, meaning .await must first be called for anything to happen. 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. Arguably, actix, async-std and tokio are the three most widely used. SeaORM's underlying driver, SQLx, supports all three.

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