mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-17 14:18:27 +00:00
close websocket on disconnect
This commit is contained in:
parent
1d29f66cfc
commit
0c4028ad52
1 changed files with 32 additions and 22 deletions
|
@ -291,16 +291,23 @@ async fn hot_reload_handler(
|
|||
ws.on_upgrade(|mut socket| async move {
|
||||
log::info!("🔥 Hot Reload WebSocket connected");
|
||||
let mut rx = state.messages.subscribe();
|
||||
let hot_reload_handle = tokio::spawn(async move {
|
||||
loop {
|
||||
let read_set_rsx = rx.recv();
|
||||
let read_err = socket.recv();
|
||||
tokio::select! {
|
||||
err = read_err => {
|
||||
if let Some(Ok(Message::Text(err))) = err {
|
||||
if let Some(Ok(err)) = err {
|
||||
if let Message::Text(err) = err {
|
||||
let error: RecompileReason = serde_json::from_str(&err).unwrap();
|
||||
log::error!("{:?}", error);
|
||||
state.update.send("reload".to_string()).unwrap();
|
||||
};
|
||||
if state.update.send("reload".to_string()).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
},
|
||||
set_rsx = read_set_rsx => {
|
||||
if let Ok(rsx) = set_rsx {
|
||||
|
@ -315,6 +322,9 @@ async fn hot_reload_handler(
|
|||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
hot_reload_handle.await.unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue