From 232b5270b4372d438e0fa50905898ef7ffc43688 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Mon, 31 Jan 2022 21:38:06 -0500 Subject: [PATCH] add top level `block_on` helper --- actix-rt/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index 7fb2b632..8df89fbf 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -206,3 +206,20 @@ where { tokio::task::spawn_local(f) } + +/// Runs the provided future, blocking the current thread until the future completes. +/// +/// This is a shortcut for creating a [`System`] and calling [`System::block_on`]. +/// +/// # Examples +/// +/// ``` +/// fn main() { +/// actix_rt::block_on(async move { +/// println!("Hello world!"); +/// }); +/// } +/// ``` +pub fn block_on(fut: F) -> F::Output { + System::new().block_on(fut) +}