start method

Future<void> start(
  1. Future<void> callback()
)

Starts the worker if it is not already running.

When start is requested while the worker is already active, one extra pass is queued so tasks added near the end of the current pass are not stranded.

Implementation

Future<void> start(Future<void> Function() callback) async {
  if (_isRunning) {
    _shouldRunAgain = true;
    return;
  }

  _isRunning = true;

  try {
    do {
      _shouldRunAgain = false;
      await callback();
    } while (_shouldRunAgain);
  } finally {
    _isRunning = false;
  }
}