What is the difference between await and block_on

await pauses async code until a result is ready, while block_on runs an async block to completion on the current thread.

The await keyword suspends execution of an async function until a Future completes, while block_on runs an async block to completion on the current thread, blocking it until the result is ready. Use await inside async functions to pause and resume tasks, and use block_on in synchronous entry points like main to start the async runtime.

use std::time::Duration;

fn main() {
    trpl::block_on(async {
        println!("Starting async task");
        trpl::sleep(Duration::from_millis(500)).await;
        println!("Task complete");
    });
}