Skip to content

Instantly share code, notes, and snippets.

@sdurban

sdurban/main.dart

Created Apr 8, 2021
Embed
What would you like to do?
Event loop example
Future<void> printOrderMessage() async {
print('Awaiting user order...');
var order = await fetchUserOrder();
print('Your order is: $order');
}
Future<String> fetchUserOrder() {
return Future.delayed(Duration(seconds: 3), () => 'Large Latte');
}
Future<void> main() async {
countSeconds(4);
await printOrderMessage();
}
void countSeconds(int s) {
for (var i = 1; i <= s; i++) {
Future.delayed(Duration(seconds: i), () => print(i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment