async/await with tokio for concurrent I/O without blocking threads

Marcus Chen Jan 2026
1 tab
use tokio::time::{sleep, Duration};

async fn fetch_data() -> String {
    sleep(Duration::from_millis(100)).await;
    "data".to_string()
}

#[tokio::main]
async fn main() {
    let result = fetch_data().await;
    println!("Fetched: {}", result);
}
1 file · rust Explain with highlit

Rust's async/await syntax lets you write asynchronous code that looks synchronous. An async fn returns a Future, which is a lazy computation. Calling .await yields control until the future is ready, allowing other tasks to run. Tokio is the most popular async runtime; it provides a scheduler, timers, and async I/O primitives. The key is that async is zero-cost: futures compile to state machines, and there's no heap allocation per task. I use async for network servers, database clients, and any I/O-heavy workload. The ergonomics are similar to Go or Node.js, but with Rust's safety guarantees. The catch is that async Rust has a steeper learning curve (lifetimes in futures, Send bounds), but it's worth it for high-performance services.