[][src]Function tokio::task::block_in_place

pub fn block_in_place<F, R>(f: F) -> R where
    F: FnOnce() -> R, 
This is supported on feature="rt-core" and feature="rt-threaded" only.

Run the provided blocking function without blocking the executor.

In general, issuing a blocking call or performing a lot of compute in a future without yielding is not okay, as it may prevent the executor from driving other futures forward. If you run a closure through this method, the current executor thread will relegate all its executor duties to another (possibly new) thread, and only then poll the task. Note that this requires additional synchronization.

Examples

use tokio::task;

task::block_in_place(move || {
    // do some compute-heavy work or call synchronous code
});