Created
May 12, 2019 01:46
-
-
Save wyattbiker/9c475329f25f6be533ae824fcc149a23 to your computer and use it in GitHub Desktop.
Stream example
This file contains hidden or 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
// asynchronous data | |
main() async { | |
// Duration interval = Duration(seconds: 1); | |
// Stream<int> stream = Stream<int>.periodic(interval, callback); | |
// List l=[1,2,1,2,3,4,5,6]; | |
// Stream stream = Stream.fromIterable(l); | |
Map<dynamic, int> map = {1: 1, 'a': 10, 'b': 20, 3: 2, 4: 4, 6: 5}; | |
Stream stream = Stream.fromIterable(map.entries); | |
await stream | |
.where((i) => i.key.runtimeType == int) | |
// .takeWhile((i) => i.runtimeType == String) | |
.listen((i) => print(i.value)) | |
.onDone(() => print("done")); | |
print("Running"); | |
// await for(int i in stream){ | |
// print(i); | |
// } | |
} | |
// This callback modify the given value to even number. | |
int callback(int value) { | |
return (value + 1) * 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment