diff --git a/src/lib.rs b/src/lib.rs index def2abcf2..6cf18a2ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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: F) -> CpuFuture + where + F: FnOnce() -> Result + Send + 'static, + I: Send + 'static, + E: Send + std::fmt::Debug + 'static, + { + crate::blocking::run(f) + } }