1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-07-01 16:55:08 +02:00

fix master branch build. change web::block output type. (#1957)

This commit is contained in:
fakeshadow
2021-02-06 08:23:59 -08:00
committed by GitHub
parent 83fb4978ad
commit 20cf0094e5
17 changed files with 98 additions and 114 deletions

View File

@ -1213,7 +1213,7 @@ mod tests {
match res {
Ok(value) => Ok(HttpResponse::Ok()
.content_type("text/plain")
.body(format!("Async with block value: {}", value))),
.body(format!("Async with block value: {:?}", value))),
Err(_) => panic!("Unexpected"),
}
}

View File

@ -274,14 +274,11 @@ pub fn service<T: IntoPattern>(path: T) -> WebService {
/// Execute blocking function on a thread pool, returns future that resolves
/// to result of the function execution.
pub async fn block<F, I, E>(f: F) -> Result<I, BlockingError<E>>
pub fn block<F, R>(f: F) -> impl Future<Output = Result<R, BlockingError>>
where
F: FnOnce() -> Result<I, E> + Send + 'static,
I: Send + 'static,
E: Send + std::fmt::Debug + 'static,
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
match actix_rt::task::spawn_blocking(f).await {
Ok(res) => res.map_err(BlockingError::Error),
Err(_) => Err(BlockingError::Canceled),
}
let fut = actix_rt::task::spawn_blocking(f);
async { fut.await.map_err(|_| BlockingError) }
}