Skip to main content

block_on

Function block_on 

Source
pub fn block_on<F>(task: impl IntoFuture<IntoFuture = F>) -> F::Output
where F: Future,
Expand description

Blocks the thread until the task future finishes.

The crate futures-lite is used to execute the task.

§Examples

Test a run call:

use zng_task as task;

pub fn run_ok() {
    let r = task::block_on(task::run(async { foo(32).await }));

    r.expect("foo(32) was not Ok");
}

§No App Context

If this is called inside an app thread a warning is logged and the app context is removed, the task never runs in an app context. This is done to avoid deadlocks where tasks depend on app updates to complete.

You should never block an app thread anyway, use UPDATES.run to run arbitrary futures, or async_hn! to declare async event handlers.