Skip to main content

spawn

Function spawn 

Source
pub fn spawn<R: Send + 'static>(
    work: impl FnOnce() -> R + Send + 'static,
    then: impl Fn(R) + 'static,
)
Expand description

Runs work on another thread — a file to read, something slow — and then then with what it made, on the interface’s thread, where it may change state.

then runs once. If the work is still going when the component that asked has left the tree, then still runs, so what it touches should say whether it is still there (StateHandle::is_mounted).