mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-27 10:39:03 +02:00
use released versions of actix-net
This commit is contained in:
@ -667,7 +667,7 @@ mod tests {
|
||||
async fn async_with_block() -> Result<HttpResponse, Error> {
|
||||
let res = web::block(move || Some(4usize).ok_or("wrong")).await;
|
||||
|
||||
match res? {
|
||||
match res {
|
||||
Ok(value) => Ok(HttpResponse::Ok()
|
||||
.content_type("text/plain")
|
||||
.body(format!("Async with block value: {}", value))),
|
||||
|
10
src/web.rs
10
src/web.rs
@ -6,6 +6,7 @@ pub use actix_http::Response as HttpResponse;
|
||||
pub use bytes::{Bytes, BytesMut};
|
||||
pub use futures::channel::oneshot::Canceled;
|
||||
|
||||
use crate::error::BlockingError;
|
||||
use crate::extract::FromRequest;
|
||||
use crate::handler::Factory;
|
||||
use crate::resource::Resource;
|
||||
@ -274,10 +275,11 @@ pub fn service(path: &str) -> WebService {
|
||||
|
||||
/// Execute blocking function on a thread pool, returns future that resolves
|
||||
/// to result of the function execution.
|
||||
pub fn block<F, R>(f: F) -> impl Future<Output = Result<R, Canceled>>
|
||||
pub async fn block<F, I, E>(f: F) -> Result<I, BlockingError<E>>
|
||||
where
|
||||
F: FnOnce() -> R + Send + 'static,
|
||||
R: Send + 'static,
|
||||
F: FnOnce() -> Result<I, E> + Send + 'static,
|
||||
I: Send + 'static,
|
||||
E: Send + std::fmt::Debug + 'static,
|
||||
{
|
||||
actix_threadpool::run(f)
|
||||
actix_threadpool::run(f).await
|
||||
}
|
||||
|
Reference in New Issue
Block a user