WasmWorker class final

One or more isolates that run WebAssembly for the calling isolate.

final worker = await WasmWorker.spawn();
final module = await worker.compile(wasmBytes);
final instance = await module.instantiate({
  'env': {'log': (int value) => print(value)},
});
print(await instance.invoke('add', [20, 22]));
await worker.dispose();

Properties

hashCode → int
The hash code for this object.
no setterinherited
isDisposed → bool
Whether the worker has been released.
no setter
pendingRequests → int
How many requests are in flight; useful for spreading load over a pool.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

compile(Uint8List bytes) → Future<RemoteModule>
Compiles bytes inside the worker.
deserialize(Uint8List blob) → Future<RemoteModule>
Loads a module from a blob produced by RemoteModule.serialize.
dispose() → Future<void>
Releases the worker's engine and store and stops its isolate.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
validate(Uint8List bytes) → Future<bool>
Whether bytes is a valid module.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

spawn({void configure(WasmConfig config)?}) → Future<WasmWorker>
Starts a worker with its own engine and store.