Last active
November 27, 2019 17:21
-
-
Save legalcodes/5c8c7716b6b4284842f15fe079f61e47 to your computer and use it in GitHub Desktop.
Why Async Matters
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
// This example shows how *not* to write asynchronous Dart code. | |
String createOrderMessage () { | |
var order = fetchUserOrder(); | |
return 'Your order is: $order'; | |
} | |
Future<String> fetchUserOrder() { | |
// Imagine that this function is more complex and slow | |
return Future.delayed(Duration(seconds: 4), () => 'Large Latte'); | |
} | |
void main () { | |
print(createOrderMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice catch, many thanks!