interval method Null safety

Stream<int> interval(
  1. num time
)

Returns a Stream of counter values which fires every time seconds.

The stream returns a counter with the number of completed intervals. The stream ends automatically after time seconds.

This method is based on the onElapsedTimeChange stream and is therefore executed before all other animatables.

await for (var counter in juggler.interval(0.5)) {
  print(counter);
}

var stream = juggler.interval(0.5).take(10);
stream.listen((counter) => print(counter));

Implementation

Stream<int> interval(num time) async* {
  var count = 0;
  var nextTime = elapsedTime + time;
  await for (var elapsedTime in onElapsedTimeChange) {
    while (elapsedTime >= nextTime) {
      yield ++count;
      nextTime = nextTime + time;
    }
  }
}