Concurrency API
Every concurrency function in one table. For when to use which, and how they fit together, read the Concurrency guide. Promise is imported from std/runtime but documented in the guide, so its rows link there.
| Function | Description | Documented in |
|---|---|---|
Task.spawn(move () => {...}) | Spawn a green task | std/runtime |
t.join() | Wait for a task to finish | std/runtime |
Promise(fn) / Promise<T>.run(fn) | Run fn on a green task, result via await | Concurrency: Promises |
Promise<T>.blocking(fn) | Run fn on an OS thread (CPU-bound / blocking FFI) | Concurrency: Promise.blocking |
p.await() | Wait for a promise's result | Concurrency: Promises |
Promise.all(v) / Promise.race(v) | Collect all results / first to finish | Concurrency: Promise.all, Promise.race |
parallelMap(v, n, f) | Divide a Vec across n OS threads, transform in place, reassemble (std/shard) | std/shard |
parallelMapWith(v, windows, states, f) | The same cycle with per-worker state and a window queue | std/shard |
parallelScanStr(s, n, overlap, f) | Divide a string into read-only windows and scan on n threads | std/shard |
Channel.new(cap) | Create bounded channel | std/sync |
ch.send(val) | Send value (blocks if full) | std/sync |
ch.recv() | Receive value (blocks if empty) | std/sync |
ch.trySend(val) | Non-blocking send, returns bool | std/sync |
ch.tryRecv() | Non-blocking receive, returns Option<T> | std/sync |
ch.close() | Signal no more values | std/sync |
ch.len() | Current items in channel | std/sync |
WaitGroup.new() | Create a wait group | std/sync |
wg.add(n) / wg.done() / wg.wait() | Track and await a fleet of tasks | std/sync |
AtomicI64.new(v) / AtomicI32.new(v) / AtomicU64.new(v) / AtomicBool.new(v) | Create atomic | std/sync |
a.load() | Atomic read | std/sync |
a.store(v) | Atomic write | std/sync |
a.add(v) / a.sub(v) | Atomic add/sub, wrapping (returns old) | std/sync |
a.cas(exp, des) | Compare-and-swap (returns old) | std/sync |
a.swap(v) | Atomic swap (returns old) | std/sync |
Once.new() | Create a run-exactly-once guard | std/sync |
o.run(fn) | Run fn once; later callers block until it finishes | std/sync |
o.isDone() | True once the initializer has completed | std/sync |
x.clone() | Give another task/worker its own owner of a channel, wait group, atomic, or Once | std/sync |