Stream results asynchronously with C# IAsyncEnumerable and channels

8 steps · about 2 h 15 min · Intermediate

  1. Generate and consume an async stream (tutorial, Microsoft Learn, 30 min)

    A guided build that pages through a web API with async iterators and await foreach.

  2. Use await foreach correctly (reference, Microsoft Learn, 15 min)

    Shows await foreach syntax, ConfigureAwait and how it differs from foreach.

  3. Read the IAsyncEnumerable<T> contract (reference, Microsoft Learn, 10 min)

    The interface behind every async stream and its GetAsyncEnumerator cancellation token.

  4. Pass cancellation into async iterators (reference, Microsoft Learn, 10 min)

    EnumeratorCancellation makes WithCancellation tokens reach your iterator body.

  5. Connect producers and consumers with channels (article, Microsoft Learn, 25 min)

    Covers bounded versus unbounded channels, full modes and the reader/writer pattern.

  6. Create bounded and unbounded channels (reference, Microsoft Learn, 10 min)

    Factory methods and options such as SingleReader and FullMode for back-pressure.

  7. Understand why channels were added (article, .NET Blog, 25 min)

    The .NET team's walkthrough of channel design and producer/consumer pipelines.

  8. Add LINQ operators for async streams (repo, GitHub, 10 min)

    Home of System.Linq.Async, which adds Where, Select and more to IAsyncEnumerable.