use std::{thread, time};
      use crossbeam_channel::unbounded;
      
      fn main() {
        let (snd, rcv) = unbounded();
        let n_msgs = 5;
        crossbeam::scope(|s| {
          s.spawn(|_| {
            for i in 0..n_msgs {
              snd.send(i).unwrap();
              thread::sleep(time::Duration::from_millis(100));
            }
          });
        }).unwrap();
        for _ in 0..n_msgs {
          let msg = rcv.recv().unwrap();
          println!("Received {}", msg);
        }
      }
      
      Rust language logo

      Pass data between threads

      Codiga's Rust Recipes

      data between threads with crossbeam

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.