counter method

StreamSubscription counter(
  1. Duration interval,
  2. dynamic task(
    1. int i
    ), {
  3. bool callOI = false,
})

Implementation

StreamSubscription counter(Duration interval, Function(int i) task,
    {bool callOI = false}) {
  final seeds = List.generate(toInt(), (e) => e);
  final stream = Stream.fromIterable(seeds).interval(interval).timeInterval();
  stream.doOnCancel(() {
    seeds.clear();
  });
  if (callOI) {
    task(0);
  }
  return stream.listen((i) {
    task(i.value);
  });
}