timespan method

Stream<num> timespan(
  1. num time
)

Returns a Stream of relative time which fires for time seconds.

The stream returns the relative time since the start of the method. 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 time in juggler.timespan(2.0)) {
  print(time);
}

var stream = juggler.timespan(2.0).map((time) => 2.0 * time);
stream.listen((value) => print(value));

Implementation

Stream<num> timespan(num time) async* {
  final startTime = elapsedTime;
  await for (var elapsedTime in onElapsedTimeChange) {
    final currentTime = elapsedTime - startTime;
    final clampedTime = currentTime < time ? currentTime : time;
    yield clampedTime;
    if (currentTime >= time) break;
  }
}