Rust Async — Async/Await, Tokio, and Futures for Concurrent I/O
DodaTech
Updated 2026-06-28
1 min read
In this tutorial, you will learn about Rust Async. We cover key concepts, practical examples, and best practices to help you master this topic.
Rust Async/Await provides zero-cost async I/O with tokio runtime, async functions, and futures for efficient concurrent operations.
What You'll Learn
- Async functions
- Tokio runtime
- Async HTTP requests
- Async file I/O
Why It Matters
Async enables high-concurrency servers. DodaZIP uses tokio for async compression. Discord uses tokio for real-time messaging.
Real-World Use
Web servers, real-time services, database access, file streaming.
[dependencies]
tokio = { version = "1", features = ["full"] }
reqwest = { version = "0.11", features = ["json"] }
use tokio::time::{sleep, Duration};
async fn say_hello() {
println!("Hello");
sleep(Duration::from_secs(1)).await;
println!("World");
}
async fn fetch_data() -> Result<String, reqwest::Error> {
let response = reqwest::get("https://httpbin.org/get").await?;
let body = response.text().await?;
Ok(body)
}
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
// Run concurrent tasks
let (result1, result2) = tokio::join!(
say_hello(),
fetch_data(),
);
if let Ok(data) = result2 {
println!("Got data: {}", &data[..100]);
}
// Spawn tasks
let handle = tokio::spawn(async {
for i in 0..5 {
println!("Task: {}", i);
sleep(Duration::from_millis(100)).await;
}
});
handle.await.unwrap();
Ok(())
}
← Previous
Rust Concurrency — Threads, Channels, and Shared State with Arc
Next →
Rust Web Servers — Building HTTP Servers with Actix-Web, Axum, and Warp
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro