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

middle

What is ScopedModel / BLoC Pattern?

junior

What is the difference between Expanded and Flexible widgets?

middle

Differentiate between Hot Restart and Hot Reload?

Bình luận

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

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