async

API Reference

Structs

struct Resumption<R, A>

A one-shot suspended effect continuation local to the worker that captured it.

Enums

enum WaitReason

Why a task is parked: the wake sources one wait registers. recv is ready when the channel has a value or closes, send when the bounded channel has room or its receiver is gone, and deadline when the monotonic clock reaches the absolute instant.

Effects

effect 'yield() -> ()

Give another ready task a chance to run. A blocking host continues immediately when no cooperative scheduler intercepts it.

effect 'wait(reasons: [WaitReason]) -> ()

Wait until any reason is ready. A resumed operation re-checks its sources, so wakes are advisory and spurious wakes just wait again. The reason list is a plain array, not a static-length one: a generic effect occurs in rows at each instantiation, and functions inferred at one arity would fail to match rows written with the bare label.

Functions

func _task_spawn<A, T>(consume arg: A, consume worker: (consume A) -> T) -> Int

The worker takes its state as an argument rather than a capture: the transfer is explicit at the boundary, and the closure itself stays environment-free.

func _task_join<T>(handle: Int) -> T

Waits for handle and transfers its result exactly once; invalid or repeated joins trap.

func _task_width() -> Int

Returns the runtime's worker-width hint, clamped by the host to at least one.

func _chan_send<T>(handle: Int, consume value: T) -> Void

Transfers value into the runtime queue identified by handle.

func _chan_take<T>(handle: Int) -> T

Removes one queued value after channel status has established that one is ready.

func _chan_ctl(handle: Int, op: Int) -> Int

Ops: 0 status (0 value ready, 1 empty and open, 2 closed and drained), 1 retain sender, 2 drop sender, 3 drop receiver, 4 register an external wait, 5 unregister, 6 park, 7 create (the handle operand carries the capacity; 0 = unbounded), 8 count this worker's external waits, 9 whether the receiver is still live, 10 atomically reserve a send slot (1 on success), 11 register a send-wait, 12 unregister one, 13 monotonic now (ns), 14 register a deadline (the handle operand, absolute ns), 15 unregister one.

func resume<R, A>(consume k: Resumption<R, A>, value: R) -> A

Deliver value to the suspended perform site and run the extent to its next suspension or completion; the return value is the extent's answer either way.

func cancel<R, A>(consume k: Resumption<R, A>) -> ()

Discard a suspended extent, unwinding every captured frame through its cleanup entries — cancellation cannot leak.