diff --git a/src/main.rs b/src/main.rs index 0954436..dd57528 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ use rumqttc::{MqttOptions, Client, QoS, LastWill}; use bytes::Bytes; use std::time::Duration; use std::thread; -use std::sync::mpsc; use std::collections::hash_map::HashMap; use prost::Message; use std::io::Cursor; @@ -156,7 +155,6 @@ struct Match { } struct TMClient { - notices: mpsc::Sender, } struct BackendMessage { @@ -164,18 +162,13 @@ struct BackendMessage { } impl TMClient { - fn new() -> (TMClient, mpsc::Receiver) { - let (tx, rx) = mpsc::channel(); - (TMClient { - notices: tx, - }, rx) + fn new() -> TMClient { + TMClient { + } } - fn process(self: &TMClient) { - match self.notices.send(tm::Notice::default()) { - Ok(_) => println!("Received notice"), - Err(error) => println!("Recv error {}", error), - } + fn process(self: &TMClient) -> Option { + Some(tm::Notice::default()) } // TODO: make send functionality @@ -282,11 +275,6 @@ fn on_match_list_update(notice: tm::Notice, event: Event) -> (Vec, return (Vec::new(), event); } -fn get_next_notice() -> tm::Notice { - thread::sleep(Duration::from_millis(1000)); - return tm::Notice::default(); -} - fn main() { let mut event = Event{ name: String::from(""), @@ -326,16 +314,12 @@ fn main() { ); let running = true; - let (tm_client, tm_notices) = TMClient::new(); - let tm_thread = thread::spawn(move || - while running { - tm_client.process(); - } - ); + let tm_client = TMClient::new(); + // Run the callback loop in the main thread while running { - match tm_notices.recv() { - Ok(notice) => { + match tm_client.process() { + Some(notice) => { let callback = callbacks.get(¬ice.id()); match callback { None => { @@ -357,11 +341,10 @@ fn main() { }, } }, - Err(error) => println!("Notice recv error: {}", error), + None => {}, } } mqtt_recv_thread.join().expect("Failed to join mqtt thread"); - tm_thread.join().expect("Failed to join tm connection thread"); }