Made TMClient have a mirrored TMConnection for sending/receiving out of band commands

master
noah metz 2024-01-18 20:36:40 -07:00
parent 1cc7150f5d
commit 751a047bd8
1 changed files with 24 additions and 7 deletions

@ -157,6 +157,14 @@ struct Match {
struct TMClient { struct TMClient {
notices: mpsc::Sender<tm::Notice>, notices: mpsc::Sender<tm::Notice>,
requests: mpsc::Receiver<tm::Notice>,
responses: mpsc::Sender<tm::Notice>,
}
struct TMConnection {
notices: mpsc::Receiver<tm::Notice>,
requests: mpsc::Sender<tm::Notice>,
responses: mpsc::Receiver<tm::Notice>,
} }
struct BackendMessage { struct BackendMessage {
@ -164,11 +172,20 @@ struct BackendMessage {
} }
impl TMClient { impl TMClient {
fn new() -> (TMClient, mpsc::Receiver<tm::Notice>) { fn new() -> (TMClient, TMConnection) {
let (tx, rx) = mpsc::channel(); let (notice_tx, notice_rx) = mpsc::channel();
(TMClient { let (request_tx, request_rx) = mpsc::channel();
notices: tx, let (response_tx, response_rx) = mpsc::channel();
}, rx) (TMClient{
notices: notice_tx,
requests: request_rx,
responses: response_tx
},
TMConnection{
notices: notice_rx,
requests: request_tx,
responses: response_rx
},)
} }
fn process(self: &TMClient) { fn process(self: &TMClient) {
@ -321,7 +338,7 @@ fn main() {
); );
let running = true; let running = true;
let (tm_client, tm_notices) = TMClient::new(); let (tm_client, tm_connection) = TMClient::new();
let tm_thread = thread::spawn(move || let tm_thread = thread::spawn(move ||
while running { while running {
tm_client.process(); tm_client.process();
@ -329,7 +346,7 @@ fn main() {
); );
while running { while running {
match tm_notices.recv() { match tm_connection.notices.recv() {
Ok(notice) => { Ok(notice) => {
let callback = callbacks.get(&notice.id()); let callback = callbacks.get(&notice.id());
match callback { match callback {