Created
July 4, 2019 12:02
-
-
Save PiN73/eff8122f948ab95d6619010e0a16aaa5 to your computer and use it in GitHub Desktop.
await for two Futures
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
void main() async { | |
int sum = await square(3) + await square(4); | |
print('3^2 + 4^2 = $sum'); | |
} | |
Future<int> square(int val) async { | |
print('${DateTime.now()} started calculating $val^2'); | |
await Future.delayed(Duration(seconds: 1)); | |
int result = val * val; | |
print('${DateTime.now()} finished calculating $val^2'); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment