Async and Practical
Futures
async and await
An async function returns a Future. await suspends until that future completes.
Program
Play the program to await an asynchronous name and greet.
futures.dart
Future<String> fetchName() async {
await Future.delayed(Duration.zero);
return 'Ada';
}
Future<void> main() async {
var name = await fetchName();
print('Hello, $name');
}
async
An `async` function returns a `Future` automatically.
await
`await` pauses the function until the future resolves.
event loop
`Future.delayed(Duration.zero)` yields to the event loop.