Function nuclei::spawn_blocking

source ·
pub fn spawn_blocking<F, T>(f: F) -> Task<T> 
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,
Expand description

Runs blocking code on a thread pool.

§Examples

Read the contents of a file:

let contents = async_global_executor::spawn_blocking(|| std::fs::read_to_string("file.txt")).await?;

Spawn a process:

use std::process::Command;

let out = async_global_executor::spawn_blocking(|| Command::new("dir").output()).await?;