From 81091ebceedee4f3b626150b4c615a503bde91ad Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 00:07:16 +0100 Subject: [PATCH] Fix build on wasm32 --- src/gateway/gateway.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gateway/gateway.rs b/src/gateway/gateway.rs index e2923c9..d10dbfb 100644 --- a/src/gateway/gateway.rs +++ b/src/gateway/gateway.rs @@ -37,7 +37,10 @@ impl Gateway { // Wait for the first hello and then spawn both tasks so we avoid nested tasks // This automatically spawns the heartbeat task, but from the main thread + #[cfg(not(target_arch = "wasm32"))] let msg: GatewayMessage = websocket_receive.next().await.unwrap().unwrap().into(); + #[cfg(target_arch = "wasm32")] + let msg: GatewayMessage = websocket_receive.next().await.unwrap().into(); let gateway_payload: types::GatewayReceivePayload = serde_json::from_str(&msg.0).unwrap(); if gateway_payload.op_code != GATEWAY_HELLO { @@ -91,11 +94,18 @@ impl Gateway { loop { let msg = self.websocket_receive.next().await; + // PRETTYFYME: Remove inline conditional compiling // This if chain can be much better but if let is unstable on stable rust + #[cfg(not(target_arch = "wasm32"))] if let Some(Ok(message)) = msg { self.handle_message(message.into()).await; continue; } + #[cfg(target_arch = "wasm32")] + if let Some(message) = msg { + self.handle_message(message.into()).await; + continue; + } // We couldn't receive the next message or it was an error, something is wrong with the websocket, close warn!("GW: Websocket is broken, stopping gateway");