summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-10-07 10:31:56 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-10-07 04:31:56 -0400
commit41ed4cd34e70683e4b2b81e11b41082e7f73f47f (patch)
tree1d297cd1c9d3480c217bd313f20ce0a5d1c5d638
parente1d49fe0fec2f0573f38d24c47c128b78cb43498 (diff)
use single thread runime in tokio_util::block_on (#3080)
-rw-r--r--cli/tokio_util.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/cli/tokio_util.rs b/cli/tokio_util.rs
index 831419759..678bb8e66 100644
--- a/cli/tokio_util.rs
+++ b/cli/tokio_util.rs
@@ -36,8 +36,10 @@ where
/// THIS IS A HACK AND SHOULD BE AVOIDED.
///
-/// This creates a new tokio runtime, with many new threads, to execute the
-/// given future. This is useful when we want to block the main runtime to
+/// This spawns a new thread and creates a single-threaded tokio runtime on that thread,
+/// to execute the given future.
+///
+/// This is useful when we want to block the main runtime to
/// resolve a future without worrying that we'll use up all the threads in the
/// main runtime.
pub fn block_on<F, R>(future: F) -> Result<R, ErrBox>
@@ -50,10 +52,7 @@ where
let (sender, receiver) = channel();
// Create a new runtime to evaluate the future asynchronously.
thread::spawn(move || {
- let r = match create_threadpool_runtime() {
- Ok(mut rt) => rt.block_on(future),
- Err(e) => Err(ErrBox::from(e)),
- };
+ let r = tokio::runtime::current_thread::block_on_all(future);
sender
.send(r)
.expect("Unable to send blocking future result")