refactor into functions

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

View File

@ -1,17 +1,26 @@
use std::thread;
use launchpad::core::events::{Event, Severity};
use std::sync::mpsc::{channel};
use std::sync::mpsc::channel;
use std::thread;
fn main() {
basic_event_test();
}
fn basic_event_test() {
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");
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");
event_sender
.send(test_event_1.unwrap())
.expect("Sending event from t1 failed");
});
let mut event_cntr = 0;
@ -21,11 +30,12 @@ fn main() {
println!("Received event {:?}", event);
event_cntr += 1;
}
Err(_) => { ()
Err(_) => {
()
// println!("Received error {:?}", error);
}
}
};
}
t0.join().unwrap();
t1.join().unwrap();
}