From 8de442113f51bf0016fd8cddb71eeba354d3e6d9 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Fri, 28 Apr 2023 21:20:10 +0200 Subject: [PATCH] fix(ws): Don't block main thread while connecting (#337) --- plugins/websocket/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/websocket/src/lib.rs b/plugins/websocket/src/lib.rs index c3e08ace..1f06da32 100644 --- a/plugins/websocket/src/lib.rs +++ b/plugins/websocket/src/lib.rs @@ -79,15 +79,14 @@ enum WebSocketMessage { } #[tauri::command] -fn connect( +async fn connect( window: Window, url: String, callback_function: CallbackFn, config: Option, ) -> Result { let id = rand::random(); - let (ws_stream, _) = - tauri::async_runtime::block_on(connect_async_with_config(url, config.map(Into::into)))?; + let (ws_stream, _) = connect_async_with_config(url, config.map(Into::into)).await?; tauri::async_runtime::spawn(async move { let (write, read) = ws_stream.split();