pub fn set_max_blocking_threads(threads: NonZeroUsize)Expand description
Set the maximum number of threads used by the backing thread pool.
ยงExample
use blocking::unblock;
use std::fs::{read_dir, File};
use std::io::prelude::*;
blocking::set_max_blocking_threads(NonZeroUsize::new(100).unwrap());
let mut files = Vec::new();
for entry in read_dir("/path/to/large/directory").unwrap() {
files.push(unblock(move || -> std::io::Result<String> {
let mut contents = String::new();
let mut file = File::open(entry?.path())?;
file.read_to_string(&mut contents)?;
Ok(contents)
}));
}