LEARN VOID / CONCURRENCY

Async & await

Start work now. Await its result when you need it.

Async execution

This example uses the explicit async host adapter. Its source is checked by the compiler; it is not a synchronous CLI entry program.

async.voidDownload source ↓
async func leaf(value: i32) -> i32:
    return value + 1

async func entry(value: i32) -> i32:
    var first = leaf(value)
    var second = leaf(value + 1)
    var a = await first
    var b = await second
    return a + b
Input 5Expected result 13

Schedule, then await

Calling an async function queues work and returns an inferred task handle. In this example, both leaf calls are made before the first await. Each leaf returns its input plus one, so input 5 produces 6 + 7 = 13.

Cooperation has a clear boundary

await suspends the current async function until its task completes. Cooperative async work does not mean the tasks execute on multiple CPU cores. Await is supported inside async functions; async function values and async value-receiver methods are outside the current subset.

Execution support

This is complete source for the explicit async host adapter. The ordinary synchronous CLI entry adapter does not run async entry functions. Task handles have no public user-written type spelling. Public builds are not yet available.