1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

export blocking via web module

This commit is contained in:
Nikolay Kim 2019-03-07 14:40:20 -08:00
parent 0e57b4ad61
commit c2a350b33f

View File

@ -77,6 +77,7 @@ pub mod web {
pub use actix_http::Response as HttpResponse;
pub use bytes::{Bytes, BytesMut};
use crate::blocking::CpuFuture;
use crate::extract::FromRequest;
use crate::handler::{AsyncFactory, Factory};
use crate::resource::Resource;
@ -234,4 +235,15 @@ pub mod web {
{
Route::new().to_async(handler)
}
/// Execute blocking function on a thread pool, returns future that resolves
/// to result of the function execution.
pub fn blocking<F, I, E>(f: F) -> CpuFuture<I, E>
where
F: FnOnce() -> Result<I, E> + Send + 'static,
I: Send + 'static,
E: Send + std::fmt::Debug + 'static,
{
crate::blocking::run(f)
}
}