start method

Future<void> start()

Starts the worker process

Implementation

Future<void> start() async {
  int processed = 0;
  final start = DateTime.now();

  Future<void> workerLogic() async {
    while (!_shouldStop) {
      try {
        // Check if we can process more jobs (concurrency limit)
        if (_runningJobs.length < _config.concurrency) {
          final jobFuture = _processNextJobWithTimeout();
          _runningJobs.add(jobFuture);

          // Remove from running set when complete
          jobFuture.whenComplete(() => _runningJobs.remove(jobFuture));

          processed++;

          // Check termination conditions
          if (_shouldTerminate(processed, start)) {
            await _gracefulShutdown();
            break;
          }
        }

        await Future.delayed(_config.delay);
      } catch (e, stack) {
        _config.onError?.call(e, stack);
      }
    }

    _shutdownCompleter.complete();
  }

  if (_config.runInBackground) {
    Future(workerLogic);
  } else {
    await workerLogic();
  }
}