Skip to main content

spawn_local

Function spawn_local 

Source
pub fn spawn_local<F>(future: F)
where F: Future<Output = ()> + 'static,
Expand description

Runs a Rust Future on the current thread.

The future must be 'static because it will be scheduled to run in the background and cannot contain any stack references.

The future will always be run on the next microtask tick even if it immediately returns Poll::Ready.

§JSPI

When called from within a JSPI context — a #[wasm_bindgen(jspi)] export or a task itself spawned from one — the task’s polls are entered through a WebAssembly.promising boundary, so sync code reached from the future may suspend via jspi_block_on_promise. The capability is inherited transitively down the spawn tree; a suspension parks only that task’s poll. In modules that never use JSPI attributes this branch compiles to a constant and no JSPI machinery is emitted.

§Panics

This function has the same panic behavior as future_to_promise.