Skip to main content

spawn_os_thread

Function spawn_os_thread 

Source
pub fn spawn_os_thread<F, T>(name: &str, f: F) -> JoinHandle<T>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,
Available on crate feature tasks only.
Expand description

Spawns an OS thread with the current tokio runtime context propagated.

This function captures the current tokio runtime handle (if available) and enters it in the newly spawned thread. This ensures that code running in the spawned thread can use [Handle::current()], [Handle::spawn_blocking()], and other tokio utilities that require a runtime context.