Skip to content

Commit 4152553

Browse files
committed
Prevent the events channel from closing
1 parent 51ecae3 commit 4152553

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

rust/agama-server/src/agama-web-server.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use agama_server::{
3131
logs::init_logging,
3232
web::{self, run_monitor},
3333
};
34+
use agama_utils::api::event::Receiver;
3435
use anyhow::Context;
3536
use axum::{
3637
extract::Request as AxumRequest,
@@ -322,7 +323,8 @@ async fn serve_command(args: ServeArgs) -> anyhow::Result<()> {
322323
let (tx, _) = channel(16);
323324
run_monitor(tx.clone()).await?;
324325

325-
let (events_tx, _) = channel(16);
326+
let (events_tx, events_rx) = channel(16);
327+
monitor_events_channel(events_rx);
326328

327329
let config = web::ServiceConfig::load()?;
328330

@@ -381,6 +383,18 @@ fn write_token(path: &str, secret: &str) -> anyhow::Result<()> {
381383
Ok(token.write(path)?)
382384
}
383385

386+
// Keep the receiver running to avoid the channel being closed.
387+
fn monitor_events_channel(mut events_rx: Receiver) {
388+
tokio::spawn(async move {
389+
loop {
390+
if let Err(error) = events_rx.recv().await {
391+
eprintln!("Error receiving events: {error}");
392+
break;
393+
}
394+
}
395+
});
396+
}
397+
384398
/// Represents the result of execution.
385399
pub enum CliResult {
386400
/// Successful execution.

0 commit comments

Comments
 (0)