Skip to main content

spawn

Function spawn 

Source
pub fn spawn<F, Fut>(
    name: &str,
    stop: CancellationToken,
    make: F,
) -> Result<LocalTask>
where F: FnOnce(CancellationToken) -> Fut + Send + 'static, Fut: Future<Output = ()>,
Expand description

Runs make on a dedicated thread, in a current-thread runtime.

make is called on that thread, so it may build values that are not Send. Only the closure has to cross. The returned handle cancels stop, which make gets to watch.

ยงErrors

Fails if the runtime or the thread cannot be started.