Skip to content

IAsyncEnumerable with yield in C#: sample moved to async-csharp/IAsyncEnumerableWithYield on .NET 10 - #2291

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/59560-csharp-async-enumerable-yield
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/59560-csharp-async-enumerable-yield

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample for https://code-maze.com/csharp-async-enumerable-yield/ ("IAsyncEnumerable with yield in C#").

The sample used to live in the standalone repository CodeMazeBlog/async-enumerable-yield-csharp (net6.0, Startup.cs, Swashbuckle 5.6.3, no tests). This PR moves it into async-csharp/IAsyncEnumerableWithYield, next to CancellationTokensIAsyncEnumerable. The old repository is not changed by this PR.

What is in the folder:

  • TaskOfIEnumerable, SyncYield and IAsyncEnumerableWithYield: the three console programs the article walks through (Task<IEnumerable>, synchronous yield return, async IAsyncEnumerable with await foreach), each a net10.0 top-level Program.cs that matches the article's code.
  • IAsyncEnumerableWithYieldApi: net10.0 Web API on minimal hosting (one Program.cs, no Startup class, no Swashbuckle). ValuesController, a minimal API endpoint at /items, and an EF Core ItemsController that streams rows with AsNoTracking().AsAsyncEnumerable() over SQLite (created and seeded at startup, so nothing external is needed). The launch profile keeps https://localhost:5001 and http://localhost:5000.
  • Tests (MSTest): /api/values and /items deliver their first item before the last, the EF Core query runs no command until it is enumerated, and /api/items returns every row. No test needs a live resource.

Packages (NuGet re-queried 2026-10-11, latest listed stable):

  • Microsoft.EntityFrameworkCore.Sqlite 10.0.12
  • Microsoft.AspNetCore.Mvc.Testing 10.0.12
  • Microsoft.NET.Test.Sdk 18.10.1
  • MSTest.TestAdapter 4.5.1
  • MSTest.TestFramework 4.5.1
  • coverlet.collector 10.1.0

Checked locally on SDK 10.0.302, runtime 10.0.10: dotnet build -c Release 0 warnings, 0 errors; dotnet test 4 passed, 0 failed; dotnet list package --vulnerable --include-transitive reports no vulnerable packages in any of the five projects.

Moves the "IAsyncEnumerable with yield in C#" sample from the standalone
async-enumerable-yield-csharp repository into async-csharp/IAsyncEnumerableWithYield.

- Three console programs on net10.0 with top-level statements, one per step of
  the article: Task<IEnumerable<int>>, synchronous yield return, and
  async IAsyncEnumerable<int> consumed with await foreach.
- Web API on minimal hosting (one Program.cs, no Startup class, no Swashbuckle):
  ValuesController, a minimal API endpoint, and an EF Core ItemsController that
  streams rows with AsNoTracking().AsAsyncEnumerable() over SQLite.
- MSTest tests: both endpoints deliver their first item before the last, the EF
  Core query runs no command until it is enumerated, and the items endpoint
  returns every row.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant