Skip to main content

spawn_async

Function spawn_async 

Source
pub fn spawn_async<R: Send + 'static>(
    work: impl Future<Output = R> + Send + 'static,
    then: impl Fn(R) + 'static,
)
Expand description

Awaits work — something that waits rather than works: an answer from the person, a response from a server — and then runs then with what it gave, on the interface’s thread.

The asynchronous counterpart of spawn, and the one that works on the Web, where nothing may block: a spawn there runs on the page’s only thread. Natively work is driven by the shell’s executor, which waits without holding a thread, so it must be Send and must not block — a blocking call is spawn’s.