switched to runtime instead of tokio::spawn

This commit is contained in:
Nickiel12 2024-08-20 20:53:13 -07:00
parent a7cad3781d
commit c65bce0a69

View file

@ -6,6 +6,7 @@ use async_channel::{Receiver, Sender};
use futures_util::stream::{SplitSink, SplitStream, StreamExt}; use futures_util::stream::{SplitSink, SplitStream, StreamExt};
use futures_util::SinkExt; use futures_util::SinkExt;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use tokio::runtime::Handle;
use tokio::{ use tokio::{
net::TcpStream, net::TcpStream,
sync::oneshot sync::oneshot
@ -34,7 +35,8 @@ pub type AppReceiver = Receiver<ApplicationMessage>;
#[instrument(skip(result_oneshot))] #[instrument(skip(result_oneshot))]
pub async fn connect_to_server( pub async fn connect_to_server(
connection_string: String, connection_string: String,
result_oneshot: oneshot::Sender<Result<(AppSender, AppReceiver), tungstenite_error>> result_oneshot: oneshot::Sender<Result<(AppSender, AppReceiver), tungstenite_error>>,
rt: Handle,
) { ) {
debug!("Connecting to parent!"); debug!("Connecting to parent!");
@ -67,11 +69,11 @@ pub async fn connect_to_server(
let receiver_is_closed = Arc::new(AtomicBool::new(false)); let receiver_is_closed = Arc::new(AtomicBool::new(false));
let moved_copy = receiver_is_closed.clone(); let moved_copy = receiver_is_closed.clone();
tokio::spawn(async move { rt.spawn(async move {
listen_to_ws_task(to_app_events as AppSender, moved_copy, ws_recv) listen_to_ws_task(to_app_events as AppSender, moved_copy, ws_recv)
}); });
tokio::spawn(async move { rt.spawn(async move {
send_to_wc_task(to_core_reciever, receiver_is_closed, ws_sender) send_to_wc_task(to_core_reciever, receiver_is_closed, ws_sender)
}); });