Câu hỏi phỏng vấn Flutter
Câu hỏi

Explain async , awa...

Câu trả lời

Async and await are keywords used in Dart to handle asynchronous code. Here's how they work:

async

The async keyword is used to mark a function as asynchronous. It allows the function to use await and returns a Future by default[1][2].

When you call an async function, it immediately returns a Future object. The function's body continues executing in the background while the Future is returned[1][4].

await

The await keyword is used inside async functions to wait for a Future to complete before continuing execution[1][2][4]. It suspends the execution of the async function until the awaited Future completes[3].

When an await expression is evaluated, the asynchronous function is paused, and the control returns to the caller until the Future completes[5].

Execution flow

An async function runs synchronously until the first await keyword. All synchronous code before the first await executes immediately[5].

After the await, the function is paused until the awaited Future completes. Then, the function resumes execution[3][5].

Example

dart Copy
Future<String> fetchUserOrder() {
  // Imagine that this function is more complex and slow.
  retur...
senior

senior

Gợi ý câu hỏi phỏng vấn

middle

What is the difference between Scaffold and Container in Flutter?

middle

Differentiate between Hot Restart and Hot Reload?

senior

How does Dart AOT work?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào