mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 20:53:06 +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,30 +291,40 @@ async fn hot_reload_handler(
|
|||
ws.on_upgrade(|mut socket| async move {
|
||||
log::info!("🔥 Hot Reload WebSocket connected");
|
||||
let mut rx = state.messages.subscribe();
|
||||
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 {
|
||||
let error: RecompileReason = serde_json::from_str(&err).unwrap();
|
||||
log::error!("{:?}", error);
|
||||
state.update.send("reload".to_string()).unwrap();
|
||||
};
|
||||
},
|
||||
set_rsx = read_set_rsx => {
|
||||
if let Ok(rsx) = set_rsx{
|
||||
if socket
|
||||
.send(Message::Text(serde_json::to_string(&rsx).unwrap()))
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
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(err)) = err {
|
||||
if let Message::Text(err) = err {
|
||||
let error: RecompileReason = serde_json::from_str(&err).unwrap();
|
||||
log::error!("{:?}", error);
|
||||
if state.update.send("reload".to_string()).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
};
|
||||
}
|
||||
},
|
||||
set_rsx = read_set_rsx => {
|
||||
if let Ok(rsx) = set_rsx {
|
||||
if socket
|
||||
.send(Message::Text(serde_json::to_string(&rsx).unwrap()))
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
hot_reload_handle.await.unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue