[][src]Macro smol::blocking

macro_rules! blocking {
    ($($expr:tt)*) => { ... };
}

Spawns blocking code onto a thread.

Note that blocking!(expr) is just syntax sugar for Task::blocking(async move { foo }).await.

Examples

Read a file to string:

use smol::blocking;
use std::fs;

let contents = blocking!(fs::read_to_string("file.txt"))?;

Spawn a process:

use smol::blocking;
use std::process::Command;

let out = blocking!(Command::new("dir").output())?;