diff options
Diffstat (limited to 'cli/tokio_util.rs')
-rw-r--r-- | cli/tokio_util.rs | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/cli/tokio_util.rs b/cli/tokio_util.rs index e5878cdf7..0e1257da7 100644 --- a/cli/tokio_util.rs +++ b/cli/tokio_util.rs @@ -1,30 +1,19 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -// TODO(ry) rename to run_local ? -pub fn run_basic<F, R>(future: F) -> R -where - F: std::future::Future<Output = R> + 'static, -{ - let mut rt = tokio::runtime::Builder::new() +pub fn create_basic_runtime() -> tokio::runtime::Runtime { + tokio::runtime::Builder::new() .basic_scheduler() .enable_io() .enable_time() .build() - .unwrap(); - rt.block_on(future) + .unwrap() } -// TODO(ry) maybe replace with tokio::task::spawn_blocking -#[cfg(test)] -pub fn spawn_thread<F, R>(f: F) -> impl std::future::Future<Output = R> +// TODO(ry) rename to run_local ? +pub fn run_basic<F, R>(future: F) -> R where - F: 'static + Send + FnOnce() -> R, - R: 'static + Send, + F: std::future::Future<Output = R> + 'static, { - let (sender, receiver) = tokio::sync::oneshot::channel::<R>(); - std::thread::spawn(move || { - let result = f(); - sender.send(result) - }); - async { receiver.await.unwrap() } + let mut rt = create_basic_runtime(); + rt.block_on(future) } |