basic event sender/receiver test
This commit is contained in:
parent
d1ff7c5463
commit
0bd6190055
30
src/main.rs
30
src/main.rs
@ -1,3 +1,31 @@
|
|||||||
|
use std::thread;
|
||||||
|
use launchpad::core::events::{Event, Severity};
|
||||||
|
use std::sync::mpsc::{channel};
|
||||||
fn main() {
|
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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user