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::SinkExt;
use serde::{Serialize, Deserialize};
use tokio::runtime::Handle;
use tokio::{
net::TcpStream,
sync::oneshot
@ -34,7 +35,8 @@ pub type AppReceiver = Receiver<ApplicationMessage>;
#[instrument(skip(result_oneshot))]
pub async fn connect_to_server(
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!");
@ -67,11 +69,11 @@ pub async fn connect_to_server(
let receiver_is_closed = Arc::new(AtomicBool::new(false));
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)
});
tokio::spawn(async move {
rt.spawn(async move {
send_to_wc_task(to_core_reciever, receiver_is_closed, ws_sender)
});