Channels
๋ฌ์คํธ์ ์ฑ๋์ Sender์
Receiver
Rust channels have two parts: a
Sender<T>
and aReceiver<T>
. The two parts are connected via the channel, but you only see the end-points.
use std::sync::mpsc; use std::thread; fn main() { let (tx, rx) = mpsc::channel(); tx.send(10).unwrap(); tx.send(20).unwrap(); println!("Received: {:?}", rx.recv()); println!("Received: {:?}", rx.recv()); let tx2 = tx.clone(); tx2.send(30).unwrap(); println!("Received: {:?}", rx.recv()); }
์ญ์ฃผ
- ๋ฉ์ธ์ง ํจ์ฑํ๋ transmitter(tx)์ receiver(rx) ์ ๋๋ค. ๋ณดํต ์์๋ ํ๋ฅด๋ ๊ฐ์ธ(์ฑ๋) ์๋ฅ(tx)์ ๋์ด ๊ณ ๋ฌด ์ค๋ฆฌ๊ฐ ํ๋ฅ(rx)๋ก ๊ฐ๋ ํ๋ฆ์ ์๊ฐํ์๋ฉด ๋ฉ๋๋ค.