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
15
votes
3 answers

Difference between "ToListAsync()" and "AsAsyncEnumerable().ToList()"

Function need to return Task> Following both options are returning Task>, which one is more efficient? Is there any standard way here? Option 1 : Task> GetRecords() { return …
13
votes
1 answer

.net core 3.1: 'IAsyncEnumerable' does not contain a definition for 'GetAwaiter'

I have a .net core 3.1 console app. I have a method with the following signature: public async IAsyncEnumerable GetFilePathsFromRelativePathAsync(string relativePath) If I call it: private async Task>…
Murdock
  • 4,352
  • 3
  • 34
  • 63
13
votes
2 answers

IAsyncEnumerable not working in C# 8.0 preview

I was playing around with C# 8.0 preview and can't get IAsyncEnumerable to work. I tried the following public static async IAsyncEnumerable Get() { for(int i=0; i<10; i++) { await Task.Delay(100); yield return i; …
Alen Alex
  • 897
  • 4
  • 15
  • 31
13
votes
1 answer

Converting IQueryable to implement IAsyncEnumerable

I have a query in a method: private readonly IEntityReader _reader; public async Task> HandleAsync(GetCustomer query) { var result = _reader.Query() .Include(customer => customer.Organization) …
janhartmann
  • 14,713
  • 15
  • 82
  • 138
12
votes
4 answers

'AsyncEnumerableReader' reached the configured maximum size of the buffer when enumerating a value

I am using an async/await method returning IAsyncEnumerable<> to retrieve rows from a SQL Server database and provide them via a Web API .Net Core 3.0 interface. It works fine until I exceed 8192 rows. It fails for rows beyond that point. I have…
David Stevens
  • 173
  • 1
  • 1
  • 8
11
votes
5 answers

How to implement an efficient WhenEach that streams an IAsyncEnumerable of task results?

I am trying to update my toolset with the new tools offered by C# 8, and one method that seems particularly useful is a version of Task.WhenAll that returns an IAsyncEnumerable. This method should stream the task results as soon as they become…
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
9
votes
1 answer

How to return ActionResult along with async foreach and IAsyncEnumerable

I have a controller method of this signature: public async IAsyncEnumerable Get() It works fine but I need to do some request validation and return 401, 400, and other codes accordingly, which it does not support. Alternatively, the…
9
votes
4 answers

How to use C#8 IAsyncEnumerable to async-enumerate tasks run in parallel

If possible I want to create an async-enumerator for tasks launched in parallel. So first to complete is first element of the enumeration, second to finish is second element of the enumeration, etc. public static async IAsyncEnumerable
8
votes
2 answers

Pass-through for IAsyncEnumerable?

I'd like to know if there's a way I can write a function to "pass through" an IAsyncEnumerable... that is, the function will call another IAsyncEnumerable function and yield all results without having to write a foreach to do it? I find myself…
Richard Hunt
  • 303
  • 2
  • 10
8
votes
2 answers

Why is using IAsyncEnumerable slower than returning async/await Task?

I'm currently testing out C# 8's async streams, and it seems that when I try to run the application using the old pattern of of using async/await and returning Task> it seems to be faster. (I measured it using a stopwatch and tried running it…
Randel Ramirez
  • 3,671
  • 20
  • 49
  • 63
8
votes
2 answers

Read text file with IAsyncEnumerable

I came across IAsyncEnumerable while I am testing C# 8.0 features. I found remarkable examples from Anthony Chu (https://anthonychu.ca/post/async-streams-dotnet-core-3-iasyncenumerable/). It is async stream and replacement for…
phonemyatt
  • 1,287
  • 17
  • 35
7
votes
0 answers

How can I "stream" search results from a minimal API using IAsyncEnumerable in c# using .NET 6?

Overview We're moving our database access to API calls and I need to return search results from a database as they're being found using that API. The plan was to use IAsyncEnumerable, but I'm having trouble dealing with the HttpClient buffer (at…
Dasta
  • 83
  • 5
7
votes
1 answer

IAsyncEnumerable and database queries

I have three controller methods returning IAsyncEnumerable of WeatherForecast. The first one #1 uses SqlConnection and yields results from an async reader. The second one #2 uses EF Core with the ability to use AsAsyncEnumerable extension. The third…
T. Dominik
  • 406
  • 3
  • 13
7
votes
2 answers

Can (or should) I use IAsyncEnumerable instead of Task>> in a Web API Controller

I currently have a web API that fetches a row of data using FromSqlRaw(...).ToListAsync() within a repository returns this data as Ok(data.ToArray()) as Task>> through a controller. Now I am wondering whether I…
7
votes
3 answers

Factory for IAsyncEnumerable or IAsyncEnumerator

I'm wondering if there is a way to create either IAsyncEnumerable or IAsyncEnumerator via a Source object, rather like TaskCompletionSource allows one to do for tasks. In particular, TaskCompletionSource can be passed around like any other…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
1
2
3
10 11