SHARE
TWEET

Untitled

a guest Mar 26th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use rand::{thread_rng, Rng};
  2. use std::sync::mpsc;
  3.  
  4. fn main() {
  5.     let (tx, rx) = mpsc::channel();
  6.    
  7.     for (work_id, tx) in std::iter::repeat(tx).take(25).enumerate() {
  8.         std::thread::spawn(move || {
  9.             let work_time_ms = thread_rng().gen_range(0, 500);
  10.             std::thread::sleep(std::time::Duration::from_millis(work_time_ms));
  11.             tx.send(work_id)
  12.         });  
  13.     }
  14.    
  15.     while let Ok(work_id) = rx.recv() {
  16.         println!("Work {} done", work_id)
  17.     }
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top