diff options
author | Geoff Shannon <geoffpshannon@gmail.com> | 2019-08-13 21:10:26 -0700 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2019-08-13 21:10:26 -0700 |
commit | fe90d61446b592d4e95bc226edd81c5994ceaa24 (patch) | |
tree | 5fa6d758408f8225d957fccf01e6abda957c13f9 /tokio-test/src | |
parent | 338b37884a73782fe72d4e9a0616010bcd12180e (diff) |
test: add a block_on function to tokio-test (#1431)
Diffstat (limited to 'tokio-test/src')
-rw-r--r-- | tokio-test/src/lib.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tokio-test/src/lib.rs b/tokio-test/src/lib.rs index 6e6a82ad..4d13bf4d 100644 --- a/tokio-test/src/lib.rs +++ b/tokio-test/src/lib.rs @@ -14,6 +14,18 @@ pub mod io; mod macros; pub mod task; +/// Runs the provided future, blocking the current thread until the +/// future completes. +/// +/// For more information, see the documentation for +/// [`tokio::runtime::current_thread::Runtime::block_on`][runtime-block-on]. +/// +/// [runtime-block-on]: https://docs.rs/tokio/0.2.0-alpha.1/tokio/runtime/current_thread/struct.Runtime.html#method.block_on +pub fn block_on<F: std::future::Future>(future: F) -> F::Output { + let mut rt = tokio::runtime::current_thread::Runtime::new().unwrap(); + rt.block_on(future) +} + /* #[doc(hidden)] pub mod codegen { |