mirror of
https://github.com/actix/actix-web.git
synced 2024-12-30 12:00:38 +00:00
export blocking via web module
This commit is contained in:
parent
0e57b4ad61
commit
c2a350b33f
1 changed files with 12 additions and 0 deletions
12
src/lib.rs
12
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, 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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue