Function shared_channel

Source
pub fn shared_channel<T>() -> (Sender<T>, SharedReceiver<T>)
Examples found in repository?
examples/hello_server.rs (line 37)
35fn main() {
36    const N_WORKER: u32 = 4;
37    let (tx, rx) = shared_channel();
38
39    // make thread pool
40    for i in 0..N_WORKER {
41        let rx = rx.clone();
42        thread::spawn(move || worker(i, rx));
43    }
44
45    // run server forever
46    let listener = TcpListener::bind("localhost:5000").expect("failed to listen port 5000");
47    loop {
48        match listener.accept() {
49            Ok((stream, addr)) => {
50                println!("new client: {}", addr);
51                tx.send(stream).unwrap();
52            }
53            Err(e) => println!("accept error: {}", e),
54        }
55    }
56}