pub fn set_blocking_executor(
executor: impl BlockingExecutor,
) -> Result<(), Box<dyn BlockingExecutor>>Available on crate feature
async only.Expand description
Installs the blocking executor, once per process.
use dynamic_config::BlockingExecutor;
struct Threads;
impl BlockingExecutor for Threads {
fn execute(&self, work: Box<dyn FnOnce() + Send + 'static>) {
// `async_std::task::spawn_blocking(work)` and `smol::unblock`
// slot in here just as well.
std::thread::spawn(work);
}
}
// Once per process; a second call reports that one is already installed.
let _ = dynamic_config::set_blocking_executor(Threads);§Errors
If one is already installed. The rejected executor is returned rather than dropped, so a caller that wants to can tell “already set” from “failed”.