LEARN VOID / CONCURRENCY
Async & await
Start work with async functions and await their results.
Complete program for the explicit async host adapter. The result below is the returned integer.
async func ticket_total(ticket_count: i32) -> i32:
return ticket_count * 12
async func entry(ticket_count: i32) -> i32:
var pending_total = ticket_total(ticket_count)
var booking_fee = 3
var tickets = await pending_total
return tickets + booking_feeCreate a task before awaiting
Calling ticket_total queues the multiplication and returns an inferred task handle; its body does not run inline. The parent can prepare a booking fee before requesting the result. This example uses arithmetic to show scheduling, without claiming an I/O API.
Use the result when it is ready
await pending_total waits cooperatively for the ticket total. Five tickets at twelve plus a fee of three return 63. Cooperative async does not imply execution on multiple CPU cores; use parallel workers for supported independent CPU work.
Use the explicit async adapter
This is complete source for the explicit async host adapter. The ordinary synchronous CLI entry adapter does not execute async entry functions. Await is supported inside async functions; task handles have no public user-written type spelling. Async function values and async value-receiver methods remain outside the current subset. Public builds are not yet available.
What completion releases
After a task’s owning resume returns, or its worker completion is safely acquired, the runtime releases the completed execution frame’s GC root. Objects reachable only from that frame can then be collected. A caller can still await the retained result.
Retaining a task keeps its result available for repeated awaits. Once a handle, task or group is no longer observable and its work is quiescent, the Runtime can retire its records. Keeping results or growing lists yourself still consumes memory.
Await a recoverable result
Inside an async function returning a compatible result, await pending? awaits the task, then propagates an error or unwraps the success value. Cancellation and group draining still follow the enclosing scope.