startRoutine<T> method

Routine<T> startRoutine<T>(
  1. Future<T> body()
)

Starts a routine: runs body now, up to its first wait, and returns the Routine, which can be awaited for what body returns, or stopped. Its waits (nextFrame, wait, waitUntil, waitWhile, race, waitAll) end in the routines step of a later frame, after every onUpdate (docs/stage-4.md ยง3.2):

startRoutine(() async {
  while (true) {
    await wait(2);
    add(Coin());
  }
});

It stops when this object is destroyed, and is paused while it's hidden, though not during its own load. Throws a StateError before the object is added.

Implementation

Routine<T> startRoutine<T>(Future<T> Function() body) =>
    (_world ?? (throw _notAdded('it can\'t start a routine')))._start(this, this, body);