Created
August 30, 2019 04:37
-
-
Save Dalmangyi/45e3b9ab8d35da2de9e506563ad829eb to your computer and use it in GitHub Desktop.
Dart stream exam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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