Questions tagged [iasyncenumerable]

IAsyncEnumerable exposes an IAsyncEnumerator enumerator that provides asynchronous iteration over values of type T

IAsyncEnumerable<T> was introduced as part of asynchronous streams in C# 8, which allows to retrieve and generate elements asynchronously. You can consume an async stream using an await foreach loop in the same way as you consume any sequence using a foreach loop

163 questions
1
vote
1 answer

Use IAsyncEnumerable to replace Task and Action delegate

I should implement a method that can return a list of devices. The goal is to return a device as soon as one is found without waiting for the search to finish. To do this I think I use IAsyncEnumerable. The Discover method of my implementation has…
1
vote
0 answers

Return IAsyncEnumerable from .NET Framework 4.8 SignalR service

I've added a method returning an IAsyncEnumerable to my SignalR hub method. However, instead of an object array, it seems to serialize the IAsyncEnumerable object itself. Right now, the client receives the following object: { …
André Reichelt
  • 1,484
  • 18
  • 52
1
vote
0 answers

Returning IAsyncEnumerable

Could somebody please explain to me why this code works: public async IAsyncEnumerable GetAsync() { ... var reader = await connection.ExecuteReaderAsync(query, parameters); var rowParser = result.GetRowParser(); while…
toffik325
  • 161
  • 3
  • 11
1
vote
1 answer

Consuming an IAsyncEnumerable

I have one web API application that has a function that needs to stream some data. Then I have another web application that basically acts like a proxy for that. This other application does a whole lot of other stuff like handling authorization and…
Matt Burland
  • 44,552
  • 18
  • 99
  • 171
1
vote
1 answer

Streaming lines of text using IAsyncEnumerable

I want to stream an arbitrary amount of lines of plain text from an ASP.NET server to a Blazor WebAssembly client (.NET 6.0). For testing I implemented the following dummy API: [HttpGet("lines")] public async IAsyncEnumerable GetLines() { …
Frank
  • 2,738
  • 19
  • 30
1
vote
2 answers

In C#, how can I extract a block of code which yields the return?

I have several methods which all end: while (await cursor.MoveNextAsync()) { foreach (FieldServiceAppointment appointment in cursor.Current) { yield return appointment; } } For example: public async…
Brian Kessler
  • 2,187
  • 6
  • 28
  • 58
1
vote
2 answers

Trying to Get Results of an IAsyncEnumerable Method in PowerShell with a Cmdlet Written in C#

So I am trying to take an IAsyncEnumerable method and relay the results of said method in PowerShell. I understand that PowerShell does not have async support, and generally, people use the Task.GetAwaiter().GetResult() as the means to get their…
1
vote
2 answers

Exposing a push via callback message broker as an IAsyncEnumerable

I am working with a third party library which acts as an interface to a pub-sub message broker. The broker is Solace PubSub+. For subscribers, the vendor library employs a "push messages via callback" pattern. I am writing a my own wrapper library…
allmhuran
  • 4,154
  • 1
  • 8
  • 27
1
vote
1 answer

Implementation of `Stream` that sends to IAsyncEnumerable

In my .Net Core app, there's a method in a 3rd party library that writes to a System.IO.Stream interface (it takes the stream interface as an argument and writes to it) but I want that data to go to my data source that expects data as an…
Richard Hunt
  • 303
  • 2
  • 10
1
vote
0 answers

Is there value in having async in an IAsyncEnumerable function's return type?

We're writing extensions for IAsyncEnumerable. Our ultimate goal is to be able to use System.Linq.Async. Unfortunately, current namespace clashing precludes us from doing this. In the mean time we're writing our own and trying to conform to their…
dharga
  • 2,187
  • 3
  • 24
  • 33
1
vote
2 answers

Reuse a IAsyncEnumerable instance without having to iterate again

I am currently writing a method like this: public async Task GetUserByUserIdAsync(string userId) { IQueryable usersQuery = BuildQueryable(userId); bool any = await usersQuery.ExecuteQuery().AnyAsync(); if…
1
vote
1 answer

Unable to resolve service for type System.Collections.Generic.IAsyncEnumerable

I'm having this exception: System.InvalidOperationException: 'Unable to resolve service for type 'System.Collections.Generic.IAsyncEnumerable`1[MyProject.Interfaces.IFooReader]' while attempting to activate 'MyProject.Services.FooService'.' while…
Shahar Shokrani
  • 7,598
  • 9
  • 48
  • 91
1
vote
2 answers

How to await an IAsyncEnumerable while discarding the results

I have a function that returns an IAsyncEnumerable. I want to await it for completion, but I do not care about any of the results. I only care about the side effects of calling the function. How do can I easily await the IAsyncEnumerable for…
Rick de Water
  • 2,388
  • 3
  • 19
  • 37
1
vote
2 answers

Why are async methods, which return an IAsyncEnumerable, implemented as classes instead of structs?

I am curious to why async methods returning an IAsyncEnumerable compile down to a state machine, which is defined as a class instead of a struct as it usually is. See the following example: public async IAsyncEnumerable MethodOne() { …
Twenty
  • 5,234
  • 4
  • 32
  • 67
1
vote
1 answer

Entity Framework: multiple dbcontext or not? And a few other performance related question

I’m build a calendar/entry/statistics application using quite complex models with a large number of relationships between models. In general I’m concerned of performance, and are considering different strategies and are looking for input before…