From: Dessalines Date: Tue, 21 Apr 2020 21:57:20 +0000 (-0400) Subject: Adding websocket blocking. X-Git-Url: http://these/git/%22https:/image.com/%7B%60%24%7BghostArchiveUrl%7D/%7Bthis.props.imageSrc%7D?a=commitdiff_plain;h=6b58080067dbad22bfc08516ff3410a43874ca7e;p=lemmy.git Adding websocket blocking. --- diff --git a/server/src/websocket/server.rs b/server/src/websocket/server.rs index 0e7c1a4a..da5098e9 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 {