Created
March 9, 2020 16:56
-
-
Save AlexKenbo/76aab7782e4087cda303a062ded8ce3c to your computer and use it in GitHub Desktop.
Stream periodic callback
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: 2); | |
Stream<int> stream = Stream<int>.periodic(interval, callback); | |
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