From ed434303de804871b396e3b5ddaefb1cc509fec8 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sun, 1 Sep 2024 02:17:54 +0000 Subject: [PATCH] connect now returns a 'to close' flag --- src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8219515..632e0d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,7 @@ pub type AppReceiver = Receiver; pub async fn connect_to_server( connection_string: String, rt: Handle, - ) -> Result<(AppSender, AppReceiver), tungstenite_error> { + ) -> Result<(AppSender, AppReceiver, Arc), 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)); } } }