spawn static method

Future<WasmWorker> spawn({
  1. void configure(
    1. WasmConfig config
    )?,
})

Starts a worker with its own engine and store.

Implementation

static Future<WasmWorker> spawn({
  void Function(WasmConfig config)? configure,
}) async {
  final handshake = ReceivePort();
  final responses = ReceivePort();
  final isolate = await Isolate.spawn(
    _workerMain,
    _WorkerStart(handshake.sendPort, responses.sendPort, configure),
    debugName: 'WasmWorker',
  );
  final commands = await handshake.first as SendPort;
  handshake.close();
  final worker = WasmWorker._(isolate, commands, responses);
  responses.listen(worker._onMessage, onError: worker._onTransportError);
  return worker;
}