Guest User

Untitled

a guest
Dec 11th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. use std::process::exit;
  2. use std::sync::mpsc;
  3. use std::thread;
  4.  
  5. struct Hello {
  6. text: String,
  7. }
  8.  
  9. impl Hello {
  10. fn world(&self) {
  11. println!("{} World", &self.text);
  12. exit(0);
  13. }
  14. }
  15.  
  16. fn example() {
  17. let (tx, rx) = mpsc::channel();
  18.  
  19. thread::spawn(move || {
  20. let ex: Hello = Hello {
  21. text: String::from("hello"),
  22. };
  23. for _ in rx {
  24. ex.world();
  25. }
  26. });
  27.  
  28. thread::spawn(move || loop {
  29. tx.send(()).unwrap();
  30. });
  31. }
Add Comment
Please, Sign In to add comment