Concurrency (async, task, await, yield)
Silk concurrency is built around:
async fn(pausable/awaitable concurrency),task fn(parallelizable work),awaitfor promises,yield/yield *for task values.
Canonical spec + Notes: concurrency.
Notes#
- Supported forms is documented in detail: concurrency
Examples#
task inside async fn + yield *#
task fn worker (x: int) -> int {
return x + 1;
}
async fn main () -> int {
task {
let a = worker(10);
let values: int[] = yield * a;
return values[0];
}
}
Task(Promise(T)) composition: await * yield *#
async fn add1 (x: int) -> int {
return x + 1;
}
task fn produce_promises (n: int) -> Promise(int) {
var i: int = 0;
while i < n {
yield add1(i);
i = i + 1;
}
return add1(n);
}
async fn main () -> int {
task {
let t = produce_promises(3);
let values: int[] = await * yield * t;
return values[0];
}
}
See also#
- Full reference: concurrency
std::taskandstd::sync: task, sync
Source repository · Edit this page · View Markdown