Skip to main content

off_async_worker

Function off_async_worker 

Source
pub fn off_async_worker<R>(f: impl FnOnce() -> R) -> R
Expand description

Run f, handing this worker’s other tasks (and the I/O driver, if it holds it) to another thread first when called on a multi-thread runtime worker.

Synchronous and order-preserving, unlike spawn_blocking: the caller continues only after f returns, so a write that must land before the next one still does.

  • Multi-thread runtime worker: block_in_place.
  • Blocking-pool thread, or no runtime: nothing to hand off — runs f.
  • Current-thread runtime (most #[tokio::test]s): block_in_place panics there and there is no other worker to hand off to — runs f.