run static method

Future<void> run()

Starts the simulation, executing all pending actions in time-order until it finishes or is stopped.

Implementation

static Future<void> run() async {
  if (simulationHasEnded) {
    throw Exception('Simulation has already been run and ended.'
        '  To run a new simulation, use Simulator.reset().');
  }

  while (hasStepsRemaining() &&
      _simExceptions.isEmpty &&
      !_simulationEndRequested &&
      (_maxSimTime < 0 || _currentTimestamp < _maxSimTime)) {
    await tick();
  }

  for (final err in _simExceptions) {
    logger.severe(err.exception.toString(), err.exception, err.stackTrace);
    throw err.exception;
  }

  if (_currentTimestamp >= _maxSimTime && _maxSimTime > 0) {
    logger.warning('Simulation ended due to maximum simulation time.');
  }

  while (_endOfSimulationActions.isNotEmpty) {
    final endOfSimAction = _endOfSimulationActions.removeFirst();
    await endOfSimAction();
  }

  _simulationEndedCompleter.complete();
  await simulationEnded;
}