parallel library
Run WebAssembly without blocking the calling isolate, on one thread or on several.
A WasmWorker owns a wasmtime engine and store inside its own isolate;
WasmPool keeps one worker per processor so that calls can be spread over
several threads. Every operation is a Future, so a long running
WebAssembly call never blocks the UI isolate:
final worker = await WasmWorker.spawn();
final module = await worker.compile(wasmBytes);
final instance = await module.instantiate();
print(await instance.invoke('add', [20, 22]));
await worker.dispose();
final pool = await WasmPool.spawn(workers: 4);
final instance = await (await pool.load(wasmBytes)).instantiate();
final results = await instance.callAll('work', [[1], [2], [3], [4]]);
await pool.dispose();
Values cross an isolate boundary by copy, and only plain data can be sent:
null, numbers, strings, lists, maps and Uint8List. Function references
and memories stay on the worker; reach them by export name. Import objects
may contain Dart functions (which are copied to the worker) and, for
memories, tables and globals, descriptors instead of live objects.
Classes
- GlobalDescriptor
-
new WebAssembly.Global({value, mutable}, initialValue). - Limits
-
A
wasm_limits_tvalue, as used for memories and tables. - MemoryDescriptor
-
new WebAssembly.Memory({initial, maximum, shared}). - PooledInstance
- One instance per worker, so that calls can run on several threads at once.
- PooledModule
- A module that has been compiled on every worker of a WasmPool.
- RemoteInstance
- A WasmInstance that lives in a worker.
- RemoteModule
- A WasmModule that lives in a worker.
- TableDescriptor
-
new WebAssembly.Table({element, initial, maximum}). - WasmExport
- One entry of a module's export list.
- WasmExternType
- The type of an import or an export.
- WasmFuncExternType
- A function import or export, with the type WebAssembly declares for it.
- WasmFuncType
- A WebAssembly function signature: parameters and results.
- WasmGlobalExternType
- A global import or export.
- WasmImport
- One entry of a module's import list.
- WasmImportInfo
- A description of one import, as reported by PooledModule.imports.
- WasmMemoryExternType
- A memory import or export.
- WasmPool
- A set of WasmWorkers that share the work.
- WasmTableExternType
- A table import or export.
- WasmWorker
- One or more isolates that run WebAssembly for the calling isolate.
Enums
- WasmExternKind
- What kind of thing an import or an export is.
- WasmValueKind
- The kinds of value that can cross the WebAssembly boundary.
Exceptions / Errors
- WasmtimeException
- A failure reported by wasmtime itself: compiling, linking, growing a memory, setting fuel that is not configured, and so on.
- WasmTrapException
- A trap: WebAssembly execution was aborted (unreachable, out of bounds memory access, stack overflow, an uncaught host exception, ...).
- WasmWorkerException
- Raised when a worker cannot be talked to (a crash, or a released worker).