Skip to content

Instantly share code, notes, and snippets.

@Dalmangyi
Created August 30, 2019 04:37
Show Gist options
  • Save Dalmangyi/45e3b9ab8d35da2de9e506563ad829eb to your computer and use it in GitHub Desktop.
Save Dalmangyi/45e3b9ab8d35da2de9e506563ad829eb to your computer and use it in GitHub Desktop.
Dart stream exam
void main() {
//Iterable
Stream.fromIterable([1,2,3,4,5])
.listen((int x) => print('iterable : ${x}'));
//Periodic
Stream.periodic(Duration(seconds: 1), (x) => x)
.take(5)
.listen((x) => print('take : ${x}'));
//Future
Stream.fromFuture(getData())
.listen((x) => print('from Future : ${x}'));
}
Future<String> getData() async {
await Future.delayed(Duration(seconds: 5));
print("Fetched Data");
return "--Future String--";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment