[][src]Function blocking::unblock

pub async fn unblock<T, F>(f: F) -> T where
    F: FnOnce() -> T + Send + 'static,
    T: Send + 'static, 

Moves a blocking closure onto the thread pool.

Examples

Read a file into a string:

use blocking::unblock;
use std::fs;

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

Spawn a process:

use blocking::unblock;
use std::process::Command;

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