From 2f6df111832112ad012687557f66b112ef0d1ed1 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 7 Mar 2019 19:31:17 -0800 Subject: [PATCH] do not execute blocking fn if result is not required --- src/blocking.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/blocking.rs b/src/blocking.rs index 01be30dd..fc9cec29 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -41,6 +41,7 @@ thread_local! { }; } +/// Blocking operation execution error #[derive(Debug, Display)] pub enum BlockingError { #[display(fmt = "{:?}", _0)] @@ -62,13 +63,17 @@ where let (tx, rx) = oneshot::channel(); POOL.with(|pool| { pool.execute(move || { - let _ = tx.send(f()); + 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 { rx: oneshot::Receiver>, }