Skip to content

Instantly share code, notes, and snippets.

@kumar-aakash86
Created November 20, 2024 11:48
Show Gist options
  • Save kumar-aakash86/53c529ef49cb95ed35294d4afe3a7179 to your computer and use it in GitHub Desktop.
Save kumar-aakash86/53c529ef49cb95ed35294d4afe3a7179 to your computer and use it in GitHub Desktop.
Dart Async Programming
//https://dartpad.dev/?id=53c529ef49cb95ed35294d4afe3a7179
void main() {
print('Fetching data...');
// fetchData();
// String data = await fetchDataAsync();
// print(data);
// connectStream();
print('Doing other work...');
}
void fetchData() {
Future.delayed(Duration(seconds: 2), () {
print('Data fetched');
});
}
Future<String> fetchDataAsync() async {
await Future.delayed(Duration(seconds: 2));
return 'Data fetched';
}
void connectStream()async {
await for (int value in countStream()) {
print(value);
}
}
Stream<int> countStream() async* {
for (int i = 1; i <= 5; i++) {
await Future.delayed(Duration(seconds: 1));
yield i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment