Skip to content

Commit 9d9498b

Browse files
committed
Graceful UI shutdown
1 parent 695aea0 commit 9d9498b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

example_apps/game/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
6565
None
6666
};
6767

68-
let server_task = tokio::spawn(run_swim_server(addr_tx, bind_to));
68+
let server_task = tokio::spawn(run_swim_server(addr_tx, shutdown_tx, bind_to));
6969

7070
if include_ui {
7171
let ui_task = tokio::spawn(ui_server(addr_rx, shutdown_rx, SHUTDOWN_TIMEOUT, ui_port));
@@ -109,6 +109,7 @@ fn configure_logging() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
109109

110110
async fn run_swim_server(
111111
bound: oneshot::Sender<SocketAddr>,
112+
shutdown_tx: Arc<Notify>,
112113
bind_to: Option<SocketAddr>,
113114
) -> Result<(), Box<dyn Error + Send + Sync>> {
114115
let mut builder = ServerBuilder::with_plane_name("Game Plane");
@@ -131,6 +132,8 @@ async fn run_swim_server(
131132

132133
let (_, result) = futures::future::join(shutdown, task).await;
133134

135+
shutdown_tx.notify_one();
136+
134137
result?;
135138
info!("Server stopped successfully.");
136139
Ok(())

0 commit comments

Comments
 (0)