myanmarlinks
6/18/2019 - 3:43 PM

Dart Basic Part 2

Dart Basic Part 2


import 'dart:async';

Stream<int> createNumberStream(int last) async* {
  for (var i = 0; i < last; i++) {
    yield i;
  }
}

printStream(Stream stream) {
  stream.listen((s) => print(s));
}

main() async {
  var stream = createNumberStream(5);
  printStream(stream);

  var numbers = [1,2,3,4,5];
  stream = new Stream.fromIterable(numbers);
  printStream(stream);
}