proc slow(label: Str, ms: Int): Str {
hive.task.sleep(ms)
return label
}
proc main(): void {
both := await [slow("a", 40), slow("b", 40)] // one barrier, a Str[2]
echo both
echo both[1] // a static length: no guard
}proc note(text: Str): void {
hive.task.sleep(20)
echo text
}
proc main(): void {
// Nothing to resolve to, so it is a statement: a batch of side effects
// finished before the next line, each on its own thread.
await [note("first"), note("second")]
echo "both notes are in"
}await [f(a), g(b)] starts every call in its list on a thread of its own and waits for all of them, as one barrier. It is the only await there is:
x := async f().await [] is a compile error.The arguments of each call are copied before its thread starts, exactly as with async, and there is no way to cancel a call once it has started.