Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

WASI 0.2 versus WASI 0.3

After this lesson: I can tell a WASI 0.3 interface from a WASI 0.2 one and say what changed.

60 min lesson3 commandsWebAssembly lab: Wasmtime, WASI capabilities, WIT components and plugin limits

Waiting without blocking, built in

WASI 0.3, ratified on 11 June 2026, adds native async to the Component Model. A function can be async, and streams and futures are built-in types. WASI 0.2, released in January 2024, did the same jobs with pollables and stream resources.

Today you run one component built against each version and see what changed.

By the end of this lesson

Note

I can tell a WASI 0.3 interface from a WASI 0.2 one and say what changed.

Key words

WordWhat it meansExample
Async functiona function the caller need not wait onasync func
Streamvalues that arrive one after anotherstream<u8>
Futureone value that arrives laterfuture<u32>
PollableWASI 0.2's handle for something to wait on
Semantic versiona version written major.minor.patch0.3.0

The cells students fill in are left blank in this preview.

How WASI 0.2 waits: pollables

In WASI 0.2, reading a socket or a file gives an input-stream resource. To wait for bytes without freezing, the code asks the stream for a pollable and passes it to poll, which returns when something is ready.

Every interface that waits needs its own pollable, and every language has to wire them into its own async system by hand.

Run the component built for WASI 0.2

Command
docker exec wasm wasmtime run --invoke 'ticking()' clock2.wat

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Run the component built for WASI 0.3

Command
docker exec wasm wasmtime run --invoke 'ticking()' clock3.wat

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What WASI 0.3 changed

WASI 0.3 moves waiting into the Component Model itself. WIT can now say async func, stream<u8> and future<T>, so the runtime knows when a call is waiting and can run something else.

Interfaces get shorter. An HTTP handler becomes one async function that takes a request and returns a response. Wasmtime turned WASI 0.3 on by default in version 46; the option -S p3=n turns it off.

Worked example: one job in each version

JobWASI 0.2WASI 0.3
Wait for bytesinput-stream, then a pollable and pollread a stream<u8>
Sleep for a whilea pollable from the clockan async function on the clock
Answer a web requesta handler and a response out-parameterone async function, request in, response out
Run two calls at oncepoll a list of pollablesthe runtime runs async calls side by side

The cells students fill in are left blank in this preview.

Turn WASI 0.3 off and run again

Command
docker exec wasm wasmtime run -S p3=n --invoke 'ticking()' clock3.wat

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A common mistake

Warning

Many people think every WASI 0.2 component must be rebuilt once hosts move to 0.3. Wasmtime still provides the 0.2 interfaces beside the 0.3 ones, as the lab showed. A component needs rebuilding only to use async functions or streams.

Try it: two waits taking turns

Code: python
import asyncio

async def fetch(name, steps):
    # Each await hands control back, so the other task runs meanwhile.
    for n in range(steps):
        print(name, "is waiting, step", n + 1)
        await asyncio.sleep(0)
    return name + " done"

async def main():
    results = await asyncio.gather(fetch("logs", 2), fetch("prices", 3))
    print(results)

asyncio.run(main())
# Change 3 to 1. Which task finishes first now?

About this lab and its source: WebAssembly lab: Wasmtime, WASI capabilities, WIT components and plugin limits

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.