Task Asinkron vs Thread Sistem Operasi
Task di Tokio adalah green threads yang dijadwalkan secara kooperatif di atas kumpulan OS threads pekerja.
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);
}
}Catatan rekayasa pribadi dari pengoperasian sistem produksi. Pola dan tolok ukur diperbarui seiring perkembangan runtime.