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)); } } }