Skip to content

Instantly share code, notes, and snippets.

@AlexKenbo
Created March 9, 2020 16:56
Show Gist options
  • Save AlexKenbo/76aab7782e4087cda303a062ded8ce3c to your computer and use it in GitHub Desktop.
Save AlexKenbo/76aab7782e4087cda303a062ded8ce3c to your computer and use it in GitHub Desktop.
Stream periodic callback
// 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