You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In your documentation, it says:
`Future fetchUserOrder() {
// Imagine that this function is fetching user info from another service or database.
return Future.delayed(const Duration(seconds: 2), () => print('Large Latte'));
}
void main() {
fetchUserOrder();
print('Fetching user order...');
}`
"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"."
However, I believe the statement "Large Latte" being printed after "Fetching User Order..." isn't happening due to the specified delay of two seconds, but rather due to it being the method of a Future Object, which causes its code to enter the event queue and subsequently be executed only after all synchronous code has been executed, which would have been the case even if the duration specified had been 0 seconds.
Expected fix
Change the sentence "This is because fetchUserOrder() delays before it prints "Large Latte"." to "This is because fetchUserOrder() is asynchronous code which always is executed after synchronous code is, even without any specified delay.".
Additional context
No response
I would like to fix this problem.
I will try and fix this problem on dart.dev.
The text was updated successfully, but these errors were encountered:
Page URL
https://dart.dev/libraries/async/async-await#example-introducing-futures
Page source
No response
Describe the problem
In your documentation, it says:
`Future fetchUserOrder() {
// Imagine that this function is fetching user info from another service or database.
return Future.delayed(const Duration(seconds: 2), () => print('Large Latte'));
}
void main() {
fetchUserOrder();
print('Fetching user order...');
}`
"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"."
However, I believe the statement "Large Latte" being printed after "Fetching User Order..." isn't happening due to the specified delay of two seconds, but rather due to it being the method of a Future Object, which causes its code to enter the event queue and subsequently be executed only after all synchronous code has been executed, which would have been the case even if the duration specified had been 0 seconds.
Expected fix
Change the sentence "This is because fetchUserOrder() delays before it prints "Large Latte"." to "This is because fetchUserOrder() is asynchronous code which always is executed after synchronous code is, even without any specified delay.".
Additional context
No response
I would like to fix this problem.
The text was updated successfully, but these errors were encountered: