runSchedule method

void runSchedule(
  1. ScheduleLabel label
)

Runs the named schedule, then flushes deferred commands.

A system may run another schedule inline; the inner run completes (and flushes) before its caller resumes. Re-entering a schedule already on the stack is a cycle and throws rather than overflowing it.

Implementation

void runSchedule(ScheduleLabel label) {
  if (!_finalized) {
    throw StateError('Call start() before running schedules.');
  }
  final schedule = _schedules[label];
  if (schedule == null) {
    throw StateError('Unknown schedule: ${label.id}');
  }
  if (_running.contains(label)) {
    throw StateError(
      'Recursive schedule run: '
      '${[..._running, label].map((l) => l.id).join(' -> ')}. A schedule '
      'cannot run itself, directly or through another schedule.',
    );
  }
  _running.add(label);
  try {
    schedule.run(world, profiler);
    world.commands.apply();
  } finally {
    _running.removeLast();
  }
}