Scope::spawn
pub fn spawn<R>(unit -> R body) -> Task<R> Import
Source: use task::{Scope}; compiler/src/prelude/task.hy Starts body as a child task of this scope and returns its handle.
The task begins running at the caller’s next suspension point (an IO wait,
sleep, join, yield_now or the end of the scope). Capture what it needs
with use (…).
Called on a Scope value as value.spawn(…).
Parameters#
| Name | Type |
|---|---|
body | unit -> R |
Returns#
Task<R>
Examples#
use task::{scope, Scope};
use tests::assert;
let total = scope(fn (Scope s) {
let a = s.spawn(fn () => 20);
let b = s.spawn(fn () => 22);
return (a.join() ?? 0) + (b.join() ?? 0);
});
assert!((total ?? 0) == 42);
See also#
task::sleeptask::yield_nowScope: A runningscope, used to start child tasks withspawn.