Fix inbound handle reading
This commit is contained in:
parent
91dd7839fe
commit
c4c927cc9d
22
src/main.rs
22
src/main.rs
@ -33,7 +33,7 @@ async fn main() -> AppResult<()> {
|
|||||||
info!("Starting ir remote");
|
info!("Starting ir remote");
|
||||||
|
|
||||||
let (outbound_serial_tx, outbound_serial_rx) = channel(100);
|
let (outbound_serial_tx, outbound_serial_rx) = channel(100);
|
||||||
let (inbound_serial_tx, inbound_serial_rx) = channel(100);
|
let (inbound_serial_tx, mut inbound_serial_rx) = channel(100);
|
||||||
|
|
||||||
let agent_handle: Option<JoinHandle<AppResult<()>>> = if options.no_serial {
|
let agent_handle: Option<JoinHandle<AppResult<()>>> = if options.no_serial {
|
||||||
warn!("Not starting serial port agent (--no-serial was given)");
|
warn!("Not starting serial port agent (--no-serial was given)");
|
||||||
@ -48,6 +48,15 @@ async fn main() -> AppResult<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Consume inbound_serial_rx, otherwise it will fill up and eventually be dropped
|
// TODO: Consume inbound_serial_rx, otherwise it will fill up and eventually be dropped
|
||||||
|
let inbound_serial_handle = (!options.no_serial).then(|| {
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
while let Some(m) = inbound_serial_rx.recv().await {
|
||||||
|
info!("Got message from inbound channel: {m}");
|
||||||
|
}
|
||||||
|
|
||||||
|
error!("Inbound serial receiver errored");
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
// let (agent_shutdown_tx, agent_handle): (Sender<()>, JoinHandle<AppResult<()>>) = {
|
// let (agent_shutdown_tx, agent_handle): (Sender<()>, JoinHandle<AppResult<()>>) = {
|
||||||
|
|
||||||
@ -68,10 +77,13 @@ async fn main() -> AppResult<()> {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
tokio::select!(
|
tokio::select!(
|
||||||
// TODO: Handle the case where agent_handle is enabled or disabled
|
// TODO: Find a better way to do this. Unwrap is called before if statement, so unwrap_or_else must be used
|
||||||
// r = agent_handle.unwrap(), if agent_handle.is_some() => {
|
r = agent_handle.unwrap_or_else(|| tokio::task::spawn(async move {Ok(())})), if agent_handle.is_some() => {
|
||||||
// error!("Agent handle ended: {r:?}");
|
error!("Agent handle ended: {r:?}");
|
||||||
// }
|
}
|
||||||
|
r = inbound_serial_handle.unwrap_or_else(|| tokio::task::spawn(async move {()})), if inbound_serial_handle.is_some() => {
|
||||||
|
error!("Inbound serial handle ended: {r:?}");
|
||||||
|
}
|
||||||
r = webui_handle => {
|
r = webui_handle => {
|
||||||
// agent_shutdown_tx.send(()).await?;
|
// agent_shutdown_tx.send(()).await?;
|
||||||
error!("Webserver handle ended: {r:?}");
|
error!("Webserver handle ended: {r:?}");
|
||||||
|
@ -58,7 +58,6 @@ fn inbound(port: Box<dyn SerialPort>, inbound_serial_tx: Sender<String>) -> AppR
|
|||||||
return Err(e.into());
|
return Err(e.into());
|
||||||
}
|
}
|
||||||
Ok(m) => {
|
Ok(m) => {
|
||||||
info!("Got message from inbound channel: {m}");
|
|
||||||
inbound_serial_tx.blocking_send(m)?;
|
inbound_serial_tx.blocking_send(m)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user