trpl-zh-cn/listings/ch16-fearless-concurrency/listing-16-09/src/main.rs

16 lines
306 B
Rust
Raw Normal View History

2022-02-06 16:43:51 +08:00
use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let val = String::from("hi");
tx.send(val).unwrap();
println!("val is {}", val);
});
let received = rx.recv().unwrap();
println!("Got: {}", received);
}