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

What's the difference betwe...

Câu trả lời

The main difference between async and async* in Dart is the type of result they return:

  • async functions return a Future, representing a single asynchronous result[1][2][3].
  • async* functions return a Stream, representing a sequence of asynchronous results[1][2].

Here's a more detailed comparison:

async

  • Used for asynchronous operations that return a single result, like making an API request[1][3].
  • The function body runs until it reaches an await expression, then pauses until the awaited Future completes[3].
  • Returns a Future that completes with the return value of the function[1][3].

Example:

dart Copy
Future<int> doSomeLongTask() async {
  await Future.delayed(Duration(seconds: 1));
  return 42;
}

async*

  • Used to create a function that returns a sequence of asynchronous results[1][2].
  • The function body runs until it reaches a yield statement, then p...
senior

senior

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

junior

Does Flutter work like a browser? How is it different from a WebView based application?

middle

What is release mode and when do you use it?

middle

Why is the build() method on State and not Stateful Widget?

Bình luận

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

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