add method

Future<void> add({
  1. String? tag,
})

Adds a new worker to the pool and starts it.

Optionally specify a tag for the new worker.

Implementation

Future<void> add({String? tag}) async {
  tag ??= 'worker_${_workers.length + 1}';
  final worker = IsolateWorker(tag: tag, useLogger: useLogger);
  await worker.start();
  _workers.add(worker);
  if (_workers.length == 1) {
    _next = 0;
  }
  _eventController.add(IsolateWorkerPoolEvent(IsolateWorkerPoolEventType.add, worker._tag));
}