Interview frequency: …
Short answer
An async function returns a Future, and await waits for the Future to complete inside the function without blocking the execution thread, passing the result or error clearly.
Explanation
A Future represents a result that may arrive later. await suspends the rest of the current function until the operation completes, but it does not turn the operation synchronous and does not freeze the event loop. Handle errors with try/catch, and make sure every important Future is either awaited or managed explicitly.
Code example
Future<String> loadName() async {
final response = await fetchName();
return response;
}
try {
final name = await loadName();
} catch (error) {
handle(error);
}Common mistakes
- Thinking await means running the operation on another isolate.
- Forgetting await and then treating the Future as if it were the final value.