diff options
Diffstat (limited to 'src/doc/book/listings/ch16-fearless-concurrency/listing-16-10/src/main.rs')
-rw-r--r-- | src/doc/book/listings/ch16-fearless-concurrency/listing-16-10/src/main.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch16-fearless-concurrency/listing-16-10/src/main.rs b/src/doc/book/listings/ch16-fearless-concurrency/listing-16-10/src/main.rs new file mode 100644 index 000000000..82b220de4 --- /dev/null +++ b/src/doc/book/listings/ch16-fearless-concurrency/listing-16-10/src/main.rs @@ -0,0 +1,25 @@ +use std::sync::mpsc; +use std::thread; +use std::time::Duration; + +fn main() { + let (tx, rx) = mpsc::channel(); + + thread::spawn(move || { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("thread"), + ]; + + for val in vals { + tx.send(val).unwrap(); + thread::sleep(Duration::from_secs(1)); + } + }); + + for received in rx { + println!("Got: {}", received); + } +} |