component

command
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Component Model & async

This example runs six things through the component package that upstream wazero does not support:

  1. An interface export — instantiate adder.wasm and call component:adder/calc#add(2, 3), passing and receiving lifted Component Model values.
  2. A WASI 0.2 command — a genuine rustc wasm32-wasip2 wasi:cli/command (hello.wasm) with WASI stdio wired up, run to print hello world.
  3. An async export — async_first_light.wasm exports run-async, a Component Model async (callback-ABI) export. From the embedder it is called exactly like a synchronous export; the async scheduler is driven transparently underneath, and the call returns once the task completes.
  4. A thread — thread.wasm (source: testdata/thread.wat) spawns a Component Model thread with thread.new-indirect and hands control to it with thread.yield-then-resume; the worker thread resolves the task. It is still a single blocking Call from Go.
  5. Multi-threaded map-reduce — multithread.wasm (source: testdata/multithread.wat) spawns five Component Model threads over one shared array: four mappers each double their 2-element chunk, then a reducer sums the doubled array (2*(1+..+8) = 72). Real multi-threaded array processing, cooperatively scheduled inside the guest. (CM thread.* is currently only reachable from hand-authored .wat — no Rust toolchain emits it, and wazy does not implement wasi-threads spawn, so this is the genuine article for CM threads.)
  6. CallAsync — await_import.wasm awaits an async import get() -> u32. The host registers it with component.WithAsyncImport and completes it from another goroutine (real I/O in a real host). inst.CallAsync returns a PendingCall the moment the guest parks; PendingCall.Await resumes it once the external Resolve lands — the flow a blocking Call cannot express.

Run it:

go run .
component:adder/calc add(2, 3) = 5
wasi:cli hello: hello world
async run-async() = 42
thread (spawn + resume) = 99
multithread map-reduce (4 mappers + reducer) = 72
callasync run-async() = 42 (was parked until the external goroutine resolved)

The .wasm files under testdata are the same real component binaries exercised by wazy's own conformance tests.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL