spawn static method

Future<WasmPool> spawn({
  1. int? workers,
  2. void configure(
    1. WasmConfig config
    )?,
})

Starts workers workers, each with its own engine, store and thread.

Defaults to the number of processors, capped at 8.

Implementation

static Future<WasmPool> spawn({
  int? workers,
  void Function(WasmConfig config)? configure,
}) async {
  final count = workers ?? Platform.numberOfProcessors.clamp(1, 8);
  if (count < 1) throw RangeError.range(count, 1, null, 'workers');
  final created = <WasmWorker>[];
  try {
    for (var i = 0; i < count; i++) {
      created.add(await WasmWorker.spawn(configure: configure));
    }
  } catch (_) {
    for (final worker in created) {
      await worker.dispose();
    }
    rethrow;
  }
  return WasmPool._(created);
}