From 472c8349ac7169e39484a3cc41ef76dbd2d4d3db Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 9 Jun 2022 16:59:38 +0200 Subject: [PATCH] refactor into functions --- src/main.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2550b36..073a188 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); }