ready method

Future<void> ready()

Ensure that all pending tree operations finish.

This is mainly intended for testing purposes: awaiting on this future ensures that the game is fully loaded, and that all pending operations of adding the components into the tree are fully materialized.

Warning: awaiting on a game that was not fully connected will result in an infinite loop. For example, this could occur if you run x.add(y) but then forget to mount x into the game.

Implementation

Future<void> ready() async {
  var repeat = true;
  while (repeat) {
    // Give chance to other futures to execute first
    await Future<void>.delayed(Duration.zero);
    repeat = false;
    processLifecycleEvents();
    repeat |= hasLifecycleEvents;
  }
}