What’s the difference between async and async* in Dart?

Technology CommunityCategory: FlutterWhat’s the difference between async and async* in Dart?
VietMX Staff asked 3 years ago
  • async gives you a Future while async* gives you a Stream
  • You add the async keyword to a function that does some work that might take a long time. It returns the result wrapped in a Future.
  • You add the async* keyword to make a function that returns a bunch of future values one at a time. The results are wrapped in a Stream.
  • async* will always returns a Stream and offer some syntax sugar to emit a value through yield keyword.