Async Tasks vs OS Threads
Tokio tasks are cooperatively scheduled green threads executing on a pool of OS threads.
src/bin/worker.rs
use tokio::sync::mpsc;
#[tokio::main]
async fn main() {
let (tx, mut rx) = mpsc::channel(32);
tokio::spawn(async move {
tx.send("pipeline-event").await.unwrap();
});
while let Some(msg) = rx.recv().await {
println!("Received: {}", msg);
}
}Personal engineering field notes compiled from production systems. Patterns and benchmarks are updated as runtimes evolve.