dotnet / dotnet/aspnetcore

[Blazor] Support for IEnumerable/IAsyncEnumerable on JS interop

Open
#63,545 2 comments 3 reactions 0 assignees View on GitHub
area-blazor copilot-candidate feature-blazor-jsinterop
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

IEnumerable and IAsyncEnumerable are "special" in the sense that they are "lazy" and allow producing more than one value. In the end, they represent a contract between the producer and the consumer in the form of the `Current` and `MoveNext` protocol.

Right now, JS interop supports returning a `Task` which is a similar type of contract in the sense that it represents a value that will be available in the future and that the framework "special cases". We can think of `IAsyncEnumerable` as a collection of values that are produced asynchronously (or the sequence version of a task).

This analogy is not accurate in formal terms, but it gets the point across that if we have built-in support for tasks, there's no reason why we wouldn't want to support IAsyncEnumerable understood as a sequence of tasks.

This would for example enable modeling scenarios like JS triggered state updates into the .NET side in a more natural way without requiring in many cases define an "equivalent" protocol.

`IAsyncEnumerable` can be supported everywhere, while `IEnumerable` can only be supported on the InProcessJsRuntime.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.