spawn static method

Future<WebTransportWorker> spawn({
  1. int workerThreads = 0,
  2. int dispatchBatchMax = 64,
  3. int chunkSize = _defaultChunkSize,
})

Spawns the worker.

Implementation

static Future<WebTransportWorker> spawn({
  int workerThreads = 0,
  int dispatchBatchMax = 64,
  int chunkSize = _defaultChunkSize,
}) async {
  final ready = ReceivePort();
  final isolate = await Isolate.spawn(
    _workerEntry,
    _WorkerBootstrap(
      ready.sendPort,
      workerThreads: workerThreads,
      dispatchBatchMax: dispatchBatchMax,
      chunkSize: chunkSize,
    ),
    debugName: 'webtransport',
    errorsAreFatal: false,
  );
  final first = await ready.first;
  ready.close();
  if (first is! SendPort) {
    isolate.kill(priority: Isolate.immediate);
    throw StateError('the webtransport worker failed to start: $first');
  }
  final worker = WebTransportWorker._(isolate, first);
  worker._receive.listen(worker._onMessage);
  return worker;
}