blob: 9adf7d8332bc7d961b792047af81f5532fde1f37 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use crate::state::{State, StatePhase};
use ipc_channel::ipc::IpcSender;
use log::*;
use mumlib::command::{Command, CommandResponse};
use std::sync::{Arc, Mutex};
use tokio::sync::mpsc;
pub async fn handle(
state: Arc<Mutex<State>>,
mut command_receiver: mpsc::UnboundedReceiver<(Command, IpcSender<Result<Option<CommandResponse>, ()>>)>,
) {
debug!("Begin listening for commands");
loop {
debug!("Enter loop");
let command = command_receiver.recv().await.unwrap();
debug!("Received command {:?}", command.0);
let mut state = state.lock().unwrap();
let (wait_for_connected, command_response) = state.handle_command(command.0).await;
if wait_for_connected {
let mut watcher = state.phase_receiver();
drop(state);
while !matches!(watcher.recv().await.unwrap(), StatePhase::Connected) {}
}
command.1.send(command_response).unwrap();
}
//TODO err if not connected
//while let Some(command) = command_receiver.recv().await {
// debug!("Parsing command {:?}", command);
//}
//debug!("Finished handling commands");
}
|