basic event sender/receiver test

This commit is contained in:
Robin Müller 2022-06-09 16:58:44 +02:00
parent d1ff7c5463
commit 0bd6190055
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -1,3 +1,31 @@
use std::thread;
use launchpad::core::events::{Event, Severity};
use std::sync::mpsc::{channel};
fn main() {
println!("hello");
let test_event_0 = Event::new(Severity::INFO, 0, 0);
let (event_sender, event_receiver) = channel();
let t0_sender = event_sender.clone();
let t0 = thread::spawn(move || {
t0_sender.send(test_event_0.unwrap()).expect("Sending event from t0 failed");
});
let test_event_1 = Event::new(Severity::MEDIUM, 1, 8);
let t1 = thread::spawn(move || {
event_sender.send(test_event_1.unwrap()).expect("Sending event from t1 failed");
});
let mut event_cntr = 0;
while event_cntr < 2 {
match event_receiver.recv() {
Ok(event) => {
println!("Received event {:?}", event);
event_cntr += 1;
}
Err(_) => { ()
// println!("Received error {:?}", error);
}
}
};
t0.join().unwrap();
t1.join().unwrap();
}