1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00

do not execute blocking fn if result is not required

This commit is contained in:
Nikolay Kim 2019-03-07 19:31:17 -08:00
parent eef687ec80
commit 2f6df11183

View File

@ -41,6 +41,7 @@ thread_local! {
}; };
} }
/// Blocking operation execution error
#[derive(Debug, Display)] #[derive(Debug, Display)]
pub enum BlockingError<E: fmt::Debug> { pub enum BlockingError<E: fmt::Debug> {
#[display(fmt = "{:?}", _0)] #[display(fmt = "{:?}", _0)]
@ -62,13 +63,17 @@ where
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
POOL.with(|pool| { POOL.with(|pool| {
pool.execute(move || { pool.execute(move || {
if !tx.is_canceled() {
let _ = tx.send(f()); let _ = tx.send(f());
}
}) })
}); });
CpuFuture { rx } CpuFuture { rx }
} }
/// Blocking operation completion future. It resolves with results
/// of blocking function execution.
pub struct CpuFuture<I, E> { pub struct CpuFuture<I, E> {
rx: oneshot::Receiver<Result<I, E>>, rx: oneshot::Receiver<Result<I, E>>,
} }