Lunatic is a runtime for WebAssembly that runs Wasm modules as lightweight processes with its own heap/stack and preemptively schedules them on a multi-threaded executor. A running Wasm module can spawn new Lunatic processes using a guest library currently available for Rust and AssemblyScript. Scheduling is implemented by modifying a Wasm module and adding "gas"/"reduction counts" (similar to Erlang).
Lunatic uses Wasmtime to JIT compile and run Wasm
LunaticModule
represents a Wasm module. It is created from a Wasm binary&[u8]
. Before creating a Wasmtime module, it modifies it using walrus by adding reduction counts and other (seemodule::normalisation
).HostFunctions
provide guest APIs for spawning processes, channels, WebAssembly System Interface (WASI), and networking (until WASI gets support for networking). An API implementsuptown_funk::HostFunctions
trait. This trait is usually implemented automatically usinguptown_funk_macro
.LunaticLinker
abstracts Wasmtime linking. It takes a Lunatic module and an API (impl HostFunctions
) and returns an ready to execute instance.Process
(found inapi::process
module) takesLunaticModule
andHostFunctions
, links them, creates anAsyncWormhole
(see AsyncWormhole crate) and runs the Wasm instance inside it. AsyncWormhole implements theFuture
trait.