0PricingLogin
Learn Rust Coding · Lesson

Introduction to Async/Await

Learn the fundamentals of `async` functions and `await` expressions for writing asynchronous, non-blocking code.

Why Asynchronous Programming?

In programming, tasks often involve waiting. This could be waiting for a file to load, a network request to complete, or a database query to return results.

Traditionally, programs block during these waits, meaning they pause all other operations until the task finishes. This can make applications slow and unresponsive.

When Code Waits...

Consider this simple example of a blocking operation. The program will pause for 2 seconds before printing the second message.

Try running it:

use std::thread;
use std::time::Duration;

fn main() {
  println!("Starting a blocking task...");
  thread::sleep(Duration::from_secs(2)); // This blocks!
  println!("Blocking task finished!");
}

All lessons in this course

  1. Introduction to Async/Await
  2. Building Async Applications with Tokio
  3. Working with Futures and Tasks
← Back to Learn Rust Coding