Channel Structs
MPSC channel types
Sender และ Receiver
Section titled “Sender และ Receiver”use std::sync::mpsc::{channel, Sender, Receiver};use std::thread;
fn main() { // Create channel let (tx, rx): (Sender<i32>, Receiver<i32>) = channel();
// Spawn sender thread thread::spawn(move || { for i in 1..=5 { tx.send(i).unwrap(); println!("Sent: {}", i); } });
// Receive in main thread for received in rx { println!("Received: {}", received); }
println!("Channel closed");}เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google