add wasm friendly task spawning

This commit is contained in:
bitfl0wer 2023-11-22 14:23:36 +01:00
parent f8979b7feb
commit 022bf9f320
1 changed files with 6 additions and 1 deletions

View File

@ -2,6 +2,7 @@ use std::time::Duration;
use futures_util::{SinkExt, StreamExt};
use log::*;
#[cfg(not(target_arch = "wasm32"))]
use tokio::task;
use self::event::Events;
@ -74,10 +75,14 @@ impl Gateway {
};
// Now we can continuously check for messages in a different task, since we aren't going to receive another hello
// FIXME: Doesn't work in WASM
#[cfg(not(target_arch = "wasm32"))]
task::spawn(async move {
gateway.gateway_listen_task().await;
});
#[cfg(target_arch = "wasm32")]
wasm_bindgen_futures::spawn_local(async move {
gateway.gateway_listen_task().await;
});
Ok(GatewayHandle {
url: websocket_url.clone(),