From the course: Rust: Asynchronous Programming with Tokio

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

How do the sync and await methods work in Rust

How do the sync and await methods work in Rust - Rust Tutorial

From the course: Rust: Asynchronous Programming with Tokio

How do the sync and await methods work in Rust

- [Instructor] Asynchronous code and non-asynchronous code are built with the same compiler. So how does Rust tell them apart? The answer is the keywords, async and await. The async keyword is used to denote that a body of code is asynchronous. To use the async keyword, you place it at the start of your function definition. The await keyword is used as a method call on asynchronous functions. Technically speaking, await tells your program to wait for the asynchronous function to change the state from pending to done, and then it returns the value associated with that function. Now that we understand how the Rust compiler identifies asynchronous code, we now need to figure out how it runs asynchronous code. Asynchronous programming requires an asynchronous runtime. This runtime is the mechanism that allows us to start many functions at once and periodically check on them to see if they're done running. Out of the box…

Contents