Skip to main content

Module controller

Module controller 

Source
Expand description

WASM execution runtime and controller.

§Architecture

  • Runtime: Compiled WASM module. Thread-safe, shareable (Arc). Compile once, instantiate many times.

  • Controller: Per-execution instance. Single-threaded, created from Runtime. Cheap to create, can be done per-request or pooled.

§Concurrency Patterns

use std::sync::Arc;
use surrealism_runtime::{controller::Runtime, package::SurrealismPackage};

// Compile once (expensive)
let runtime = Arc::new(Runtime::new(package)?);

// For each concurrent request:
let runtime = runtime.clone();
tokio::spawn(async move {
    let context = Box::new(MyContext::new());
    let mut controller = runtime.new_controller(context).await?;
    controller.invoke(None, args).await
});

Structs§

Controller
Per-execution controller. Not thread-safe - create one per concurrent call. Lightweight, created from Runtime. Each controller has its own isolated Store and Instance.
Runtime
Compiled WASM runtime. Thread-safe, can be shared across threads via Arc. Compiles WASM once, then each controller gets its own isolated Store/Instance. The Engine, Module, and Linker are immutable and safely shared.
StoreData
Store data for WASM execution. Each Controller has its own isolated StoreData.