From 14fb5f57c494357ee730148e5c5a2d7641d2081a Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 21 Apr 2020 17:57:20 -0400 Subject: [PATCH] Adding websocket blocking. --- server/src/websocket/server.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/src/websocket/server.rs b/server/src/websocket/server.rs index 0e7c1a4af..da5098e91 100644 --- a/server/src/websocket/server.rs +++ b/server/src/websocket/server.rs @@ -896,10 +896,18 @@ where let data = data.to_string(); let op2 = op.clone(); + let fut = async move { - let parsed_data: Data = serde_json::from_str(&data)?; - let res = Oper::new(parsed_data).perform(pool, Some(ws_info))?; - to_json_string(&op, &res) + actix_web::web::block(move || { + let parsed_data: Data = serde_json::from_str(&data)?; + let res = Oper::new(parsed_data).perform(pool, Some(ws_info))?; + to_json_string(&op, &res) + }) + .await + .map_err(|e| match e { + actix_web::error::BlockingError::Error(e) => e, + _ => APIError::err("Operation canceled").into(), + }) }; match op2 {