wasm_async (wasm v0.16.0)

View Source

The async Canonical ABI runtime (Component Model async, not a WASI version).

The async ABI lets a component export or import an async func and carry typed future<T>/stream<T> values, with structured concurrency built from tasks, waitable-sets and subtasks. wit-bindgen compiles even a synchronous-looking async fn into a component that imports the async built-ins (task.return, context.get/set, waitable-set.*, stream.*/future.*, waitable.join) and exports an [async-lift] function with a callback, so the whole substrate has to exist.

The BEAM makes the executor cheap: the process running the call is the task, a wait is a selective receive, and readiness arrives as a message from a producer. wasm_component_link binds each async canon built-in to builtin/2 here, and wasm_component:call_async/4 drives an [async-lift] export: it calls the core function, decodes the status, and on WAIT waits on the named waitable-set and re-enters the guest through its callback until it returns EXIT.

The runtime separates three concerns (like wasmtime): a pending operation (a blocked read records its destination), the data state a producer message ingests into (a future's value, a stream's buffered bytes, a close - retained regardless of whether a read is pending yet), and event delivery (an operation is deliverable only when it has a pending read AND its data can satisfy it, at which point the copy into guest memory happens and exactly one event is produced). A WAIT never manufactures a completion; it delivers only from ingested state.

i32 sentinels are signed: BLOCKED is -1, since the operand stack holds signed Erlang integers.

Where its state lives

It is in the process dictionary of the process that owns the component instance: the frame (the tasks, handles, waitable-sets and producers of the calls into the instance), the frames set aside by a task started inside another, and each component instance's cooperative threads. A fiber's or an explicit thread's own process keeps only the keys that say whom it serves. Every key is {wasm_async, ...}, and each is declared as a macro near the top of this file with a line saying what it holds.

It is there because the async built-ins are host functions. builtin/2 answers a fun(Ctx, Flats) that the interpreter calls in that process and that returns only its results, so nothing carries a frame from one built-in call to the next; the process is the task. wasm_resources keeps its handle tables, and wasm_component its host resource table, in the same process for the same reason. The consequence is the one wasm_component:destroy/1 states: one live component instance per process, destroyed from that process.

Where things are

The banners divide the file in this order.

bannerwhat is there
%%% task frameopening, joining and closing a frame: begin_task/2, leave_call/0, end_task/0, close_frame/0, nested/1, take_return/0, resolved/0
%%% host-created endsa stream or future the host makes for a call: new_future_readable/2, new_stream_readable/2, new_future_channel/1, new_stream_channel/1,2, register_producer/2,3, deliver_before/2; and backpressure/1
%%% built-insbuiltin/2: what each async canon built-in does
%%% copiesstream.read, stream.write, future.read and future.write into and out of guest memory
%%% subtasksan async-lowered import called as a subtask: async_lower/2,3, subtask.cancel, fiber_waiting/1, take_produced/1
%%% wait (executor) sidewait_on_set/1: blocking until a waitable-set has an event, then delivering it
%%% waitable-set statewhich set each waitable is in
%%% producersthe processes that feed a read, and stopping them
%%% tasks after their calla task that runs on after its call returned: suspend_task/4, pending/0, pump/1
%%% fibersa stackful task run in a fiber process: owner_side/1, reenter/1, start_fiber/1, suspend_fiber/1
%%% cooperative threadsthe thread built-ins and their scheduler: quiet/1, drop_threads/1, guest_call/1
%%% host endsthe host's side of a stream or future: host_reader/1, host_sink/2,3, host_stream/1, host_future/1, on_end/2, host_write/3, host_close/1, host_future_resolve/2, host_read/3, host_future_await/2
%%% buffersa stream's buffered values, as a binary for stream<u8> and a list otherwise
%%% helperssync_call/3, which lets a synchronous call use the built-ins; handle_counter/0, raise_handle_counter/1

Summary

Functions

The core function an async-lowered import (canon lower with the async option) binds to. The guest calls it with the lowered arguments plus a return-area pointer, expecting a subtask status back. Sig is the import's {Params, Result}; Fun the host implementation. This synchronous form runs the host function inline, writes its result into the return area, and reports RETURNED at once, with no subtask handle (as the specification has it for a call that has already resolved).

How far the guest instance Inst has raised backpressure (backpressure.inc less backpressure.dec). While it is above zero the instance takes no new async call.

Start a task frame for the current process. Inst is the instance that owns the guest memory the built-ins read and write (the lift core's, which Ctx does not expose when that core imports its memory). Opts may carry wait_hook => Pid, notified each time the task enters wait_on_set (so a test can release a producer only after the owner is provably waiting). Mints a fresh task reference so a producer that outlives its call cannot bleed messages into the next.

The core function a given async canon built-in binds to. Each returns fun(Ctx, Flats) -> {ok, Results} | {trap, Reason} (the resource-intrinsic contract). Meta carries what the built-in's encoding declares: elem, the element type of a stream or future built-in, and async, whether a copy may return BLOCKED rather than wait in place.

Tear the frame down whatever is still running in it: stop every producer, drop every pending task and every end. wasm_component:destroy/1 calls it.

Queue a completion for Handle in the owner's own mailbox before the guest runs, so a later wait_on_set finds it without blocking (the before-WAIT / retained-readiness case). Info is as for register_producer/2.

Stop every thread of the component instance Comp and forget its threads table. wasm_component:destroy/1 calls it.

Tear the task frame down: stop producers, clear state, flush stale messages.

Whether a fiber of component instance Comp waits in the frame.

Forget the host functions kept under Keys (take_owner_keys/0).

Run Fun, a realloc the host calls in the guest, as the specification has it run: in a thread of its own, whose context slots start at zero. The caller's slots are put back after. wasi-libc relies on it: its cabi_realloc runs on a stack of its own and leaves slot 0, the stack pointer, at zero.

Run Fun, a call into the guest, counted as running: the host-end calls answer {error, reentrant} meanwhile instead of running tasks inside it.

The next stream, future or waitable handle this process gives out.

End the host's writer W: the guest's reader sees the end of the stream.

As host_stream/1, for a future: resolve it with host_future_resolve/2.

Wait for the guest to resolve the future whose reader the host holds: {ok, Value}, {error, dropped} if the guest dropped its writer first, or as host_read/3.

Resolve the host's future writer W with Value.

Read at most Max elements from the host's reader H, running the pending tasks until there are some: {ok, Elements}, eof once the guest has dropped its writer and everything was read, {error, timeout} past Timeout milliseconds, or the error that stopped a task.

Take the guest's readable end H as the host's: from now on the host reads it, with host_read/3, while the guest writes. Its buffer is bounded as between two guest ends, so a writer waits until the host reads.

Take the guest's readable end H as the host's and hand everything the guest writes to it to Sink, as it is written: Sink(Elements) answers ok, or closed to drop the end so the guest's next write sees it gone. When the guest drops its writer, Sink(eof) is called once. Suits a destination that takes data at once, such as stdout or a file.

As host_sink/2, taking at most Max elements from each write: a larger write completes with Max written, and the guest writes the rest again. A file's sink uses it, so a guest learns the host does not take writes of any size at once.

A new stream of Desc elements the host writes and the guest reads: {Reader, Writer}. Give the guest Reader (an import result or argument); write with host_write/3 and end it with host_close/1.

Write Items (a binary for stream<u8>, else a list) to the host's writer W, running the pending tasks while the guest's buffer is full. ok once all is written; {error, dropped} if the guest dropped its end; {error, timeout} past Timeout milliseconds.

End a started call whose task has finished, leaving the frame as it is: the host may still read what the task returned, such as a response's body. pump/1 or close_frame/0 tears it down once the host is done.

Run Fun, a call from inside a guest call into another component's async export, in the running call's frame: the two share their streams, futures and tasks, so an end one hands the other is the same end. What the running call keeps for itself (its instance, context slots and options) is put back after.

Create the readable end of a CHANNEL future: no value yet, so future.read blocks until a producer ingests {value, V} (via a message) and the executor delivers it.

Create the readable end of a future already holding Value (EAGER): the guest's future.read completes at once, no wait. Used by call_async for a future<T> parameter whose value is known up front.

Create the readable end of a CHANNEL stream<T>: empty and open, so stream.read blocks until a producer ingests {data, Elements} / close and the executor delivers.

As new_stream_channel/1, applying Map to each {data, Items} a producer sends, in the owner's process, before the guest reads it. A producer can then send what only the owner can turn into an element, such as a socket it accepted, which becomes a resource handle in the owner's table.

Create the readable end of an EAGER stream<T> already holding Elements, its writer already dropped. A stream<u8> takes a binary, any other element type a list.

Run Fun() once, in the owner, when the guest drops the readable end H, or when the frame is torn down with it still open: the host that made a stream learns when nobody reads it any more, as a socket's receive stream must.

Wrap a core function the host provides to a guest (an import, an async built-in, a resource intrinsic): run in a fiber, it is run by the owner, which holds the frame and the host's resources, and its answer, or what it raised, comes back to the fiber.

How many tasks still run in this process's frame.

Run the pending tasks until every one has finished (finished), none can make progress (idle: each waits for something only the host can give, such as room in a stream the host reads), or Timeout milliseconds pass (timeout). Answers how it stopped and how many tasks remain, or {error, Reason} when a task traps. Once nothing is pending and the host holds no end, the frame is torn down. {error, reentrant} from inside a guest call.

Whether the component instance Comp holds nothing an image cannot keep: no task frame open with work in it (a pending task, a host-held end) and no thread. A snapshot of it is refused otherwise.

Make sure no handle below N is given out again, as a restored instance's guest may hold or have dropped one: the counter never goes down.

Run Fun, a call back into a guest, where the guest's call is: in the fiber the owner is serving, if it is serving one, else here.

Spawn and monitor a producer for the channel end Handle. PFun is called in the new process with #{owner, task_ref, handle} and sends {async_ready, TaskRef, Handle, Info} (Info = {value,V} | {data,Elements} | close, or for an async import's subtask subtask_complete | {subtask_complete, Result}) to the owner when it chooses. A Result of {in_owner, Make} is made by Make() in the owner when the guest is told, for a result that holds a resource handle.

As register_producer/2, with Extra merged into the map the producer gets: an async host import's producer is given the import's own result as value, so a timer knows how long to wait.

The value the running task has handed to task.return so far, left in place, or undefined. A task can resolve and keep running.

Run Call, a stackful task's whole guest call, in a fiber of its own, and serve it until it ends ({done, Result}) or waits ({waiting, Fiber}, for suspend_fiber/2). Its stack is its own, so while it waits the caller below it goes on.

Keep a waiting fiber as a task of the frame, as suspend_task/4 keeps a callback task: the executor resumes it once its wait has an event.

Keep the running task in the frame after its call returns: it has resolved (task.return) and its callback asked to wait on Set (Code 2) or to be called again (Code 1). pump/1 and the host-end calls give it its turns.

Run Fun, a call into a synchronously lifted export, with Inst, the lift's core, and Comp, its component instance, as those the async built-ins it calls act on: a synchronous task may wait, read and write streams as an async one.

The core function a synchronous lower of an async host import binds to: a canon lower without the async option, of a function whose type is async. The guest passes its arguments as any synchronous call does and gets the result back the same way, so the call blocks its thread until the host function has resolved. PFun is the producer of the three-argument async_lower/3, or none.

The keys of the host functions owner_side/1 has kept since the last call: wasm_component takes them when it has linked an instance, and gives them to forget_owner_funs/1 when it destroys it.

The value a guest producer wrote to a future/stream it returned: the future's value, or every element a stream received (a binary for stream<u8>, else a list). call_async reads this from the returned handle before the task frame is torn down.

The value the task handed back through task.return, or undefined.

The current task's reference (producers tag their messages with it).

As owner_side/1, for a built-in that acts on the calling thread alone (a context slot): an explicit thread runs it in its own process.

Block the task until a member of waitable-set Set has a deliverable completion, then perform the copy into guest memory and return {event, EventCode, Waitable, ReturnCode} for the executor to hand to the callback. {error, Reason} when a producer fails without supplying what a pending copy needs, or when nothing is left that could end the wait. Called by wasm_component:call_async/4 on a WAIT status.

How many times the task blocked in wait_on_set (reset per task).

Functions

async_lower/2

-spec async_lower({[wasm_canon:desc()], wasm_canon:desc() | none}, fun(([term()]) -> term())) ->
                     function().

The core function an async-lowered import (canon lower with the async option) binds to. The guest calls it with the lowered arguments plus a return-area pointer, expecting a subtask status back. Sig is the import's {Params, Result}; Fun the host implementation. This synchronous form runs the host function inline, writes its result into the return area, and reports RETURNED at once, with no subtask handle (as the specification has it for a call that has already resolved).

The three-argument form is the suspending case: the host function's result is computed but delivered later, unless the function answers {returned, Value}, which completes the call at once. The lowered call records a pending subtask, spawns a producer (PFun, given the subtask handle) that signals completion when it chooses, and reports the subtask STARTED, so the guest suspends. When the completion arrives the executor writes the result into the return area and delivers a SUBTASK event to resume the guest.

async_lower/3

-spec async_lower({[wasm_canon:desc()], wasm_canon:desc() | none},
                  fun(([term()]) -> term()),
                  fun((map()) -> any())) ->
                     function().

backpressure(Inst)

-spec backpressure(wasm:instance()) -> non_neg_integer().

How far the guest instance Inst has raised backpressure (backpressure.inc less backpressure.dec). While it is above zero the instance takes no new async call.

begin_task(Inst, Opts)

-spec begin_task(wasm:instance(), map()) -> ok.

Start a task frame for the current process. Inst is the instance that owns the guest memory the built-ins read and write (the lift core's, which Ctx does not expose when that core imports its memory). Opts may carry wait_hook => Pid, notified each time the task enters wait_on_set (so a test can release a producer only after the owner is provably waiting). Mints a fresh task reference so a producer that outlives its call cannot bleed messages into the next.

builtin/2

-spec builtin(atom(), map()) -> function().

The core function a given async canon built-in binds to. Each returns fun(Ctx, Flats) -> {ok, Results} | {trap, Reason} (the resource-intrinsic contract). Meta carries what the built-in's encoding declares: elem, the element type of a stream or future built-in, and async, whether a copy may return BLOCKED rather than wait in place.

close_frame()

-spec close_frame() -> ok.

Tear the frame down whatever is still running in it: stop every producer, drop every pending task and every end. wasm_component:destroy/1 calls it.

deliver_before(Handle, Info)

-spec deliver_before(non_neg_integer(), term()) -> ok.

Queue a completion for Handle in the owner's own mailbox before the guest runs, so a later wait_on_set finds it without blocking (the before-WAIT / retained-readiness case). Info is as for register_producer/2.

drop_threads(Comp)

-spec drop_threads(term()) -> ok.

Stop every thread of the component instance Comp and forget its threads table. wasm_component:destroy/1 calls it.

end_task()

-spec end_task() -> ok.

Tear the task frame down: stop producers, clear state, flush stale messages.

fiber_waiting/1

-spec fiber_waiting(term()) -> boolean().

Whether a fiber of component instance Comp waits in the frame.

forget_owner_funs(Keys)

-spec forget_owner_funs([pos_integer()]) -> ok.

Forget the host functions kept under Keys (take_owner_keys/0).

fresh_context(Fun)

-spec fresh_context(fun(() -> T)) -> T.

Run Fun, a realloc the host calls in the guest, as the specification has it run: in a thread of its own, whose context slots start at zero. The caller's slots are put back after. wasi-libc relies on it: its cabi_realloc runs on a stack of its own and leaves slot 0, the stack pointer, at zero.

guest_call(Fun)

-spec guest_call(fun(() -> T)) -> T.

Run Fun, a call into the guest, counted as running: the host-end calls answer {error, reentrant} meanwhile instead of running tasks inside it.

handle_counter()

-spec handle_counter() -> pos_integer().

The next stream, future or waitable handle this process gives out.

host_close(H)

-spec host_close(non_neg_integer()) -> ok.

End the host's writer W: the guest's reader sees the end of the stream.

host_future(Desc)

-spec host_future(wasm_canon:desc()) -> {non_neg_integer(), non_neg_integer()}.

As host_stream/1, for a future: resolve it with host_future_resolve/2.

host_future_await(H, Timeout)

-spec host_future_await(non_neg_integer(), timeout()) -> {ok, term()} | {error, term()}.

Wait for the guest to resolve the future whose reader the host holds: {ok, Value}, {error, dropped} if the guest dropped its writer first, or as host_read/3.

host_future_resolve(W, Value)

-spec host_future_resolve(non_neg_integer(), term()) -> ok | {error, term()}.

Resolve the host's future writer W with Value.

host_read(H, Max, Timeout)

-spec host_read(non_neg_integer(), pos_integer(), timeout()) ->
                   {ok, binary() | [term()]} | eof | {error, term()}.

Read at most Max elements from the host's reader H, running the pending tasks until there are some: {ok, Elements}, eof once the guest has dropped its writer and everything was read, {error, timeout} past Timeout milliseconds, or the error that stopped a task.

host_reader(H)

-spec host_reader(non_neg_integer()) -> ok | {error, term()}.

Take the guest's readable end H as the host's: from now on the host reads it, with host_read/3, while the guest writes. Its buffer is bounded as between two guest ends, so a writer waits until the host reads.

host_sink(H, Sink)

-spec host_sink(non_neg_integer(), fun((binary() | [term()] | eof) -> ok | closed)) ->
                   ok | {error, term()}.

Take the guest's readable end H as the host's and hand everything the guest writes to it to Sink, as it is written: Sink(Elements) answers ok, or closed to drop the end so the guest's next write sees it gone. When the guest drops its writer, Sink(eof) is called once. Suits a destination that takes data at once, such as stdout or a file.

host_sink(H, Sink, Max)

-spec host_sink(non_neg_integer(),
                fun((binary() | [term()] | eof) -> ok | closed),
                pos_integer() | infinity) ->
                   ok | {error, term()}.

As host_sink/2, taking at most Max elements from each write: a larger write completes with Max written, and the guest writes the rest again. A file's sink uses it, so a guest learns the host does not take writes of any size at once.

host_stream(Desc)

-spec host_stream(wasm_canon:desc()) -> {non_neg_integer(), non_neg_integer()}.

A new stream of Desc elements the host writes and the guest reads: {Reader, Writer}. Give the guest Reader (an import result or argument); write with host_write/3 and end it with host_close/1.

host_write(W, Items, Timeout)

-spec host_write(non_neg_integer(), binary() | [term()], timeout()) -> ok | {error, term()}.

Write Items (a binary for stream<u8>, else a list) to the host's writer W, running the pending tasks while the guest's buffer is full. ok once all is written; {error, dropped} if the guest dropped its end; {error, timeout} past Timeout milliseconds.

leave_call()

-spec leave_call() -> ok.

End a started call whose task has finished, leaving the frame as it is: the host may still read what the task returned, such as a response's body. pump/1 or close_frame/0 tears it down once the host is done.

nested(Fun)

-spec nested(fun(() -> T)) -> T.

Run Fun, a call from inside a guest call into another component's async export, in the running call's frame: the two share their streams, futures and tasks, so an end one hands the other is the same end. What the running call keeps for itself (its instance, context slots and options) is put back after.

new_future_channel(Desc)

-spec new_future_channel(wasm_canon:desc()) -> non_neg_integer().

Create the readable end of a CHANNEL future: no value yet, so future.read blocks until a producer ingests {value, V} (via a message) and the executor delivers it.

new_future_readable(Desc, Value)

-spec new_future_readable(wasm_canon:desc(), term()) -> non_neg_integer().

Create the readable end of a future already holding Value (EAGER): the guest's future.read completes at once, no wait. Used by call_async for a future<T> parameter whose value is known up front.

new_stream_channel(Desc)

-spec new_stream_channel(wasm_canon:desc()) -> non_neg_integer().

Create the readable end of a CHANNEL stream<T>: empty and open, so stream.read blocks until a producer ingests {data, Elements} / close and the executor delivers.

new_stream_channel(Desc, Map)

-spec new_stream_channel(wasm_canon:desc(), fun(([term()]) -> [term()])) -> non_neg_integer().

As new_stream_channel/1, applying Map to each {data, Items} a producer sends, in the owner's process, before the guest reads it. A producer can then send what only the owner can turn into an element, such as a socket it accepted, which becomes a resource handle in the owner's table.

new_stream_readable(Desc, Elements)

-spec new_stream_readable(wasm_canon:desc(), binary() | [term()]) -> non_neg_integer().

Create the readable end of an EAGER stream<T> already holding Elements, its writer already dropped. A stream<u8> takes a binary, any other element type a list.

on_end(H, Fun)

-spec on_end(non_neg_integer(), fun(() -> any())) -> ok | {error, term()}.

Run Fun() once, in the owner, when the guest drops the readable end H, or when the frame is torn down with it still open: the host that made a stream learns when nobody reads it any more, as a socket's receive stream must.

owner_side(F)

-spec owner_side(function()) -> function().

Wrap a core function the host provides to a guest (an import, an async built-in, a resource intrinsic): run in a fiber, it is run by the owner, which holds the frame and the host's resources, and its answer, or what it raised, comes back to the fiber.

pending()

-spec pending() -> [reference()].

How many tasks still run in this process's frame.

pump(Timeout)

-spec pump(timeout()) -> {finished | idle | timeout, non_neg_integer()} | {error, term()}.

Run the pending tasks until every one has finished (finished), none can make progress (idle: each waits for something only the host can give, such as room in a stream the host reads), or Timeout milliseconds pass (timeout). Answers how it stopped and how many tasks remain, or {error, Reason} when a task traps. Once nothing is pending and the host holds no end, the frame is torn down. {error, reentrant} from inside a guest call.

quiet(Comp)

-spec quiet(term()) -> ok | {error, async_frame_open | threads_live}.

Whether the component instance Comp holds nothing an image cannot keep: no task frame open with work in it (a pending task, a host-held end) and no thread. A snapshot of it is refused otherwise.

raise_handle_counter(N)

-spec raise_handle_counter(pos_integer()) -> ok.

Make sure no handle below N is given out again, as a restored instance's guest may hold or have dropped one: the counter never goes down.

reenter(Fun)

-spec reenter(fun(() -> T)) -> T.

Run Fun, a call back into a guest, where the guest's call is: in the fiber the owner is serving, if it is serving one, else here.

register_producer(Handle, PFun)

-spec register_producer(non_neg_integer(), fun((map()) -> any())) -> ok.

Spawn and monitor a producer for the channel end Handle. PFun is called in the new process with #{owner, task_ref, handle} and sends {async_ready, TaskRef, Handle, Info} (Info = {value,V} | {data,Elements} | close, or for an async import's subtask subtask_complete | {subtask_complete, Result}) to the owner when it chooses. A Result of {in_owner, Make} is made by Make() in the owner when the guest is told, for a result that holds a resource handle.

register_producer(Handle, PFun, Extra)

-spec register_producer(non_neg_integer(), fun((map()) -> any()), map()) -> ok.

As register_producer/2, with Extra merged into the map the producer gets: an async host import's producer is given the import's own result as value, so a timer knows how long to wait.

resolved()

-spec resolved() -> {ok, term()} | undefined.

The value the running task has handed to task.return so far, left in place, or undefined. A task can resolve and keep running.

start_fiber(Call)

-spec start_fiber(fun(() -> term())) -> {done, term()} | {waiting, map()} | {error, term()}.

Run Call, a stackful task's whole guest call, in a fiber of its own, and serve it until it ends ({done, Result}) or waits ({waiting, Fiber}, for suspend_fiber/2). Its stack is its own, so while it waits the caller below it goes on.

suspend_fiber(F)

-spec suspend_fiber(map()) -> reference().

Keep a waiting fiber as a task of the frame, as suspend_task/4 keeps a callback task: the executor resumes it once its wait has an event.

suspend_task(Callback, Code, Set, Budget)

-spec suspend_task({wasm:instance(), binary()}, 1 | 2, non_neg_integer(), non_neg_integer()) ->
                      reference().

Keep the running task in the frame after its call returns: it has resolved (task.return) and its callback asked to wait on Set (Code 2) or to be called again (Code 1). pump/1 and the host-end calls give it its turns.

sync_call(Inst, Comp, Fun)

-spec sync_call(wasm:instance(), term(), fun(() -> T)) -> T.

Run Fun, a call into a synchronously lifted export, with Inst, the lift's core, and Comp, its component instance, as those the async built-ins it calls act on: a synchronous task may wait, read and write streams as an async one.

sync_lower/3

-spec sync_lower({[wasm_canon:desc()], wasm_canon:desc() | none},
                 fun(([term()]) -> term()),
                 fun((map()) -> any()) | none) ->
                    function().

The core function a synchronous lower of an async host import binds to: a canon lower without the async option, of a function whose type is async. The guest passes its arguments as any synchronous call does and gets the result back the same way, so the call blocks its thread until the host function has resolved. PFun is the producer of the three-argument async_lower/3, or none.

take_owner_keys()

-spec take_owner_keys() -> [pos_integer()].

The keys of the host functions owner_side/1 has kept since the last call: wasm_component takes them when it has linked an instance, and gives them to forget_owner_funs/1 when it destroys it.

take_produced(H)

-spec take_produced(non_neg_integer()) -> {ok, term()} | error.

The value a guest producer wrote to a future/stream it returned: the future's value, or every element a stream received (a binary for stream<u8>, else a list). call_async reads this from the returned handle before the task frame is torn down.

take_return()

-spec take_return() -> {ok, term()} | undefined.

The value the task handed back through task.return, or undefined.

task_ref()

-spec task_ref() -> reference() | undefined.

The current task's reference (producers tag their messages with it).

thread_side(F)

-spec thread_side(function()) -> function().

As owner_side/1, for a built-in that acts on the calling thread alone (a context slot): an explicit thread runs it in its own process.

wait_on_set(Set)

-spec wait_on_set(non_neg_integer()) ->
                     {event, non_neg_integer(), non_neg_integer(), integer()} | {error, term()}.

Block the task until a member of waitable-set Set has a deliverable completion, then perform the copy into guest memory and return {event, EventCode, Waitable, ReturnCode} for the executor to hand to the callback. {error, Reason} when a producer fails without supplying what a pending copy needs, or when nothing is left that could end the wait. Called by wasm_component:call_async/4 on a WAIT status.

waits()

-spec waits() -> non_neg_integer().

How many times the task blocked in wait_on_set (reset per task).