Guest User

Untitled

a guest
Dec 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. use std::thread;
  2. use std::sync::mpsc;
  3. use std::time::Duration;
  4.  
  5. fn main() {
  6. let (tx, rx) = mpsc::channel();
  7.  
  8. thread::spawn(move || {
  9. let vals = vec![
  10. String::from("hi"),
  11. String::from("from"),
  12. String::from("the"),
  13. String::from("thread"),
  14. ];
  15.  
  16. for val in vals {
  17. tx.send(val).unwrap();
  18. thread::sleep(Duration::from_secs(1));
  19. }
  20. });
  21.  
  22. for received in rx {
  23. println!("{:?} - Got: {}", time::now(), received);
  24. }
  25. }
Add Comment
Please, Sign In to add comment