Skip to main content

Module worker

Module worker 

Source
Expand description

Background WebAssembly workers for Oxide guest modules.

A worker is a separate .wasm module instantiated on its own OS thread with its own Wasmtime [Store], fuel budget, and linear memory. It never shares Rust types or memory with the spawning guest — communication is pure message passing of byte slices, mirroring the rest of the FFI boundary.

The spawning (“parent”) guest calls:

  • api_spawn_worker(url) → handle
  • api_worker_post_message(handle, bytes) — parent → worker inbox
  • api_worker_recv(handle) — drain one message from the worker’s outbox
  • api_worker_terminate(handle)

The worker module exports start_app() (run once on spawn) and optionally on_message(len) (run for each inbound message). Inside on_message it reads the payload with api_worker_message_read and replies with api_worker_post.

All of this is driven by polling from the guest’s frame loop, matching the WebSocket / fetch / RTC subsystems.

Structs§

WorkerState
Registry of workers spawned by one guest. Lazily created on first spawn.

Functions§

register_worker_functions
Register all api_worker_* / api_spawn_worker host functions.