Skip to main content

block_on_task

Function block_on_task 

Source
pub fn block_on_task<R, F>(task: F) -> RUMResult<R>
where F: Future<Output = R> + Send + 'static, F::Output: Send + 'static,
Expand description

Given a closure task, push it onto the current tokio runtime for execution. Every [DEFAULT_SLEEP_DURATION] seconds, we check if the task has concluded. Once the task has concluded, we call tokio::block_on to resolve and extract the task result.

Because this helper function can fail, the return value is wrapped inside a RUMResult.

ยงExample

use rumtk_core::threading::threading_functions::{init_runtime, block_on_task};

const Hello: &str = "World!";

init_runtime(5);

let result = block_on_task(async {
    Hello
}).unwrap();

assert_eq!(Hello, result, "Result mismatches expected! {} vs. {}", Hello, result);