Created
June 7, 2020 07:30
-
-
Save atn832/eb769697dffa7c7993f401ad8babf828 to your computer and use it in GitHub Desktop.
Stream demo
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
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