mirror of
https://github.com/actix/actix-extras.git
synced 2024-12-01 02:44:37 +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)]
|
#[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 || {
|
||||||
let _ = tx.send(f());
|
if !tx.is_canceled() {
|
||||||
|
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>>,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user