Skip to content

Instantly share code, notes, and snippets.

@legalcodes
Last active November 27, 2019 17:21
Show Gist options
  • Save legalcodes/5c8c7716b6b4284842f15fe079f61e47 to your computer and use it in GitHub Desktop.
Save legalcodes/5c8c7716b6b4284842f15fe079f61e47 to your computer and use it in GitHub Desktop.
Why Async Matters
// 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());
}
@galeyang
Copy link

I thought the line 14 is print(createOrderMessage()); ?

@legalcodes
Copy link
Author

Nice catch, many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment