Skip to content

Instantly share code, notes, and snippets.

@PiN73
Created July 4, 2019 12:02
Show Gist options
  • Save PiN73/eff8122f948ab95d6619010e0a16aaa5 to your computer and use it in GitHub Desktop.
Save PiN73/eff8122f948ab95d6619010e0a16aaa5 to your computer and use it in GitHub Desktop.
await for two Futures
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