[Rust] 채널
Updated:
개요
- Go의 채널과 유사
- 송/수신 채널을 지님
예제
- 코드
-
use std::sync::mpsc; use std::thread; fn main() { let (tx, rx) = mpsc::channel(); let tx1 = mpsc::Sender::clone(&tx); thread::spawn(move || { tx.send("a").unwrap(); }); thread::spawn(move || { tx1.send("b").unwrap(); }); for data in rx { println!("{}", data); } }
-
- 실행 결과
-
b a
-