pub fn block_on<T>(future: impl Future<Output = T>) -> T
Expand description

Blocks the current thread on a future.

§Examples

use futures_lite::future;

let val = future::block_on(async {
    1 + 2
});

assert_eq!(val, 3);
Examples found in repository?
examples/async_tasks/async_compute.rs (line 116)
114
115
116
117
118
119
120
121
fn handle_tasks(mut commands: Commands, mut transform_tasks: Query<&mut ComputeTransform>) {
    for mut task in &mut transform_tasks {
        if let Some(mut commands_queue) = block_on(future::poll_once(&mut task.0)) {
            // append the returned command queue to have it execute later
            commands.append(&mut commands_queue);
        }
    }
}