mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
do not execute blocking fn if result is not required
This commit is contained in:
parent
eef687ec80
commit
2f6df11183
@ -41,6 +41,7 @@ thread_local! {
|
||||
};
|
||||
}
|
||||
|
||||
/// Blocking operation execution error
|
||||
#[derive(Debug, Display)]
|
||||
pub enum BlockingError<E: fmt::Debug> {
|
||||
#[display(fmt = "{:?}", _0)]
|
||||
@ -62,13 +63,17 @@ where
|
||||
let (tx, rx) = oneshot::channel();
|
||||
POOL.with(|pool| {
|
||||
pool.execute(move || {
|
||||
if !tx.is_canceled() {
|
||||
let _ = tx.send(f());
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
CpuFuture { rx }
|
||||
}
|
||||
|
||||
/// Blocking operation completion future. It resolves with results
|
||||
/// of blocking function execution.
|
||||
pub struct CpuFuture<I, E> {
|
||||
rx: oneshot::Receiver<Result<I, E>>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user