This explanation of the printing order can be confusing:
In the preceding example, even though fetchUserOrder() executes before the print() call on line 8, the console shows the output from line 8(“Fetching user order…”) before the output from fetchUserOrder() (“Large Latte”). This is because fetchUserOrder() delays before it prints “Large Latte”.
The beginner reading this text can think that the key is in that Future.delayed() method but even if we remove the obvious delay we still will have the same behavior and output:
We know that the real reason why print('Fetching user order...') executes before print('Large Latte') from the Future is that first one in synchronous (so it runs first) and the second one firstly goes to the Event Queue and then run after all synchronous code is executed.
Expected fix
I don't know how to make it better — maybe it is too much for beginner to met the event loop mechanism from very beginning of that codelab, but for sure the current explanation can lead to misunderstanding of the principles how asynchrony works
Page URL
https://dart.dev/codelabs/async-await#example-introducing-futures
Page source
https://github.com/dart-lang/site-www/tree/main/src/codelabs/async-await.md
Describe the problem
This explanation of the printing order can be confusing:
The beginner reading this text can think that the key is in that
Future.delayed()
method but even if we remove the obvious delay we still will have the same behavior and output:We know that the real reason why
print('Fetching user order...')
executes beforeprint('Large Latte')
from the Future is that first one in synchronous (so it runs first) and the second one firstly goes to the Event Queue and then run after all synchronous code is executed.Expected fix
I don't know how to make it better — maybe it is too much for beginner to met the event loop mechanism from very beginning of that codelab, but for sure the current explanation can lead to misunderstanding of the principles how asynchrony works
Additional context
No response