Free preview.You're sampling one lesson — enroll free to unlock all 8 lessons and track your progress.
Enroll free lesson
Concurrency vs. Parallelism
Concurrency vs. Parallelism
In this lesson — part of Concurrency Basics — you'll learn concurrency vs. parallelism in Rust and why it matters in real work.
Why it matters
Modern programs wait on networks and disks — async lets them stay responsive.
Key ideas
- Blocking vs. non-blocking
- Callbacks, promises, async/await
- Concurrency vs. parallelism
- Error handling in async code
In practice
Here's how it looks in idiomatic Rust:
// Requires the `tokio` crate: tokio = { version = "1", features = ["full"] }
use tokio::time::{sleep, Duration};
async fn fetch(id: u32) -> u32 {
sleep(Duration::from_millis(10)).await; // yields without blocking the thread
id * 2
}
#[tokio::main]
async fn main() {
let (a, b) = tokio::join!(fetch(1), fetch(2)); // run concurrently
println!("{a} {b}");
}
Rust note: async fn returns a lazy Future that does nothing until .awaited, and you need an external runtime like Tokio (#[tokio::main]) because Rust's standard library ships the async syntax but not an executor.
Try it yourself
Exercise: In Rust, fetch two things concurrently and combine the results.
Recap
You now understand concurrency vs. parallelism and can apply it in Rust. Mark this lesson complete and continue to the next one.
