Skip to content

Commit

Permalink
Merge pull request #56 from mempool/junderw/use-blocking-spawn
Browse files Browse the repository at this point in the history
REST API blocking async: Solution A, block_in_place
  • Loading branch information
wiz authored Mar 6, 2024
2 parents 94b9222 + 94cfe27 commit f85bf8a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,18 @@ async fn run_server(
let uri = req.uri().clone();
let body = hyper::body::to_bytes(req.into_body()).await?;

let mut resp = handle_request(method, uri, body, &query, &config)
.unwrap_or_else(|err| {
warn!("{:?}", err);
Response::builder()
.status(err.0)
.header("Content-Type", "text/plain")
.header("X-Powered-By", &**VERSION_STRING)
.body(Body::from(err.1))
.unwrap()
});
let mut resp = tokio::task::block_in_place(|| {
handle_request(method, uri, body, &query, &config)
})
.unwrap_or_else(|err| {
warn!("{:?}", err);
Response::builder()
.status(err.0)
.header("Content-Type", "text/plain")
.header("X-Powered-By", &**VERSION_STRING)
.body(Body::from(err.1))
.unwrap()
});
if let Some(ref origins) = config.cors {
resp.headers_mut()
.insert("Access-Control-Allow-Origin", origins.parse().unwrap());
Expand Down

0 comments on commit f85bf8a

Please sign in to comment.