Skip to content

Instantly share code, notes, and snippets.

@atn832
Created June 7, 2020 07:30
Show Gist options
  • Save atn832/eb769697dffa7c7993f401ad8babf828 to your computer and use it in GitHub Desktop.
Save atn832/eb769697dffa7c7993f401ad8babf828 to your computer and use it in GitHub Desktop.
Stream demo
Stream<String> getWeather() async* {
await Future.delayed(Duration(seconds: 3));
yield "Sunny";
await Future.delayed(Duration(seconds: 3));
yield "Cloudy";
await Future.delayed(Duration(seconds: 3));
yield "Rainy";
}
void main() async {
print("Looking up weather");
await for (final weather in getWeather()) {
print(weather);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment