Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::thread;
- use std::sync::mpsc;
- 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: {}", time::now(), received);
- }
- }
Add Comment
Please, Sign In to add comment