Skip to content

instantiateWasmModule<TExports>

Instantiates a WebAssembly module, compiling it first when given bytes.

Each call makes a new instance with its own memory; nothing here keeps the instance, so dropping every reference to it lets the garbage collector free that memory. Keep it in a field cleared on unload rather than at module scope.

Import:

import { instantiateWasmModule } from '@mnaoumov/obsidian-lib/wasm';

Signature:

function instantiateWasmModule(source: ArrayBuffer | ArrayBufferView<ArrayBufferLike> | WebAssembly.Module, imports: WebAssembly.Imports): Promise<WasmInstance<TExports>>

Parameters:

Parameter Type Description
source ArrayBuffer | ArrayBufferView<ArrayBufferLike> | WebAssembly.Module The module’s bytes, or a module compiled by compileWasmModule.
imports WebAssembly.Imports The import object.

Returns: Promise<WasmInstance<TExports>> — The instance with typed exports.