0Pricing
Dart Academy · Lesson

Creating Streams With async*

Yield events from a generator.

Producing Your Own Streams

So far you consumed streams others made. Now you will produce them yourself using an async generator, the cleanest way to emit events.

The async* Keyword

Mark a function async* and it becomes a stream generator. Its return type is a Stream, and it can emit values over time. 🚿

Stream<int> countTo(int n) async* {
  // body uses yield
}

All lessons in this course

  1. Listening With await for
  2. Single vs Broadcast Streams
  3. Transforming Streams: map, where, take
  4. Creating Streams With async*
← Back to Dart Academy