Function zng_task::block_on

source ·
pub fn block_on<F>(task: F) -> F::Output
where F: Future,
Expand description

Blocks the thread until the task future finishes.

This function is useful for implementing async tests, using it in an app will probably cause the app to stop responding.

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

§Examples

Test a run call:

use zng_task as task;

#[test]
pub fn run_ok() {
    let r = task::block_on(task::run(async {
        foo(32).await
    }));
     
    r.expect("foo(32) was not Ok");
}