connect now returns a 'to close' flag

This commit is contained in:
Nickiel12 2024-09-01 02:17:54 +00:00
parent c5e733b71d
commit ed434303de

View file

@ -40,7 +40,7 @@ pub type AppReceiver = Receiver<ApplicationMessage>;
pub async fn connect_to_server(
connection_string: String,
rt: Handle,
) -> Result<(AppSender, AppReceiver), tungstenite_error> {
) -> Result<(AppSender, AppReceiver, Arc<AtomicBool>), tungstenite_error> {
debug!("Connecting to parent!");
@ -57,14 +57,15 @@ pub async fn connect_to_server(
let (ws_sender, ws_recv) = ws.split();
let receiver_is_closed = Arc::new(AtomicBool::new(false));
let moved_copy = receiver_is_closed.clone();
let rec_is_closed1 = receiver_is_closed.clone();
let rec_is_closed2 = receiver_is_closed.clone();
rt.spawn(listen_to_ws_task(to_app_events as AppSender, moved_copy, ws_recv));
rt.spawn(listen_to_ws_task(to_app_events as AppSender, rec_is_closed1, ws_recv));
rt.spawn(send_to_wc_task(to_core_reciever, receiver_is_closed, ws_sender));
rt.spawn(send_to_wc_task(to_core_reciever, rec_is_closed2, ws_sender));
info!("Websocket connect successfully");
return Ok((to_core_sender as AppSender, from_app_events as AppReceiver));
return Ok((to_core_sender as AppSender, from_app_events as AppReceiver, receiver_is_closed));
}
}
}