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
2
votes
2 answers

How to safely iterate over an IAsyncEnumerable to send a collection downstream for message processing in batches

I've watched the chat on LINQ with IAsyncEnumerable which has given me some insight on dealing with extension methods for IAsyncEnumerables, but wasn't detailed enough frankly for a real-world application, especially for my experience level, and I…
razlani
  • 23
  • 5
2
votes
0 answers

Method overloading with IAsyncEnumerable

I'm building an API that will do paging and sorting by querying a database that as a lot of entries and I stopped at a point where I'm build methods overloading and could to put that to work well, at least at the proper way I think. This is a mock…
Coastpear
  • 374
  • 2
  • 15
2
votes
1 answer

Is it possible to return a pointer to an IAsyncEnumerable in an async method?

I have an async method that processes a datareader with a delegate function that is passed to it. The purpose of the delegate is to construct domain objects out of the reader and yield those back to the caller. I would like an intermediate method…
cubesnyc
  • 1,385
  • 2
  • 15
  • 32
2
votes
1 answer

Code not executing in IAsyncEnumerable iterator, after lock in finally

I am experiencing a strange issue while enumerating an IAsyncEnumerable, with the System.Linq.Async operator Take attached to it. In my iterator I have a try-finally block with some values yielded inside the try block, and some clean-up code inside…
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
2
votes
1 answer

Parallel Linq over `IAsyncEnumerable`?

Any official or stable 3rd party library that supports using AsParallel over an IAsyncEnumerable (.NET Standard 2.1) ? I don't want to wrap an IAsyncEnumerable to an IEnumerable> with async methods, TaskCompletionSource or something…
Alsein
  • 4,268
  • 1
  • 15
  • 35
2
votes
3 answers

The correct way to await inside a foreach loop

Is this the correct way to use foreach loops whist using async ? Is there a better more efficient way? IAsyncEnumerable? (Ignore the fact that the two tables could be joined together this is a simple example) public async…
Rhodes73
  • 167
  • 2
  • 9
2
votes
1 answer

How to send IAsyncEnumerator from WebAPI and stream data through HttpClient in C# 8+?

Examples exist to read data from an IAsyncEnumerator to the UI in a Blazor app using an internal service. Examples also exist on how to send an IAsyncEnumerator as an output from a Web API Controller action. I haven't seen any examples yet how to…
2
votes
2 answers

How to stop propagating an asynchronous stream (IAsyncEnumerable)

I have a method that accepts an IAsyncEnumerable as argument, and returns also an IAsyncEnumerable. It calls a web method for each item in the input stream, and propagates the result to the output stream. My question is how can I be notified if the…
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
1
vote
2 answers

How to create IAsyncEnumerable from an enumerable of tasks

var moviePromises = this.watchlist.Select(async e => await this.GetMovieFromWatchlistEntry(e)); var movies = await Task.WhenAll(moviePromises); foreach (var movie in movies) { // dostuff } When I am doing the following it seems that all tasks…
codymanix
  • 28,510
  • 21
  • 92
  • 151
1
vote
0 answers

Stopping async iterator on exception

Is it possible to just silently terminate an IAsyncEnumerable iterator on exception? For example, my naive approach was as follows: public async IAsyncEnumerable Map(IAsyncEnumerable source, Func map) { try { …
Impworks
  • 2,647
  • 3
  • 25
  • 53
1
vote
0 answers

How to buffer a queue with a timeout?

I want to write an application where I'm reading items from a queue and processing them. Processing these items is expensive, so I want to do that in batches (of some specified amount). Moreover, I'd like to have a "timeout" mechanism that processes…
mnj
  • 2,539
  • 3
  • 29
  • 58
1
vote
0 answers

Async IAsyncEnumerable using Newtonsoft in ASP.net

I have a asp.net application that uses builder.Services.AddControllers() .AddNewtonsoftJson(); This causes the return of the controller not to run asynchronous [HttpGet("IAsyncTest")] public IAsyncEnumerable
1
vote
2 answers

Return IAsyncEnumerable from grpc with timeout try-catch

I have a gRPC client and I want to have a method that simplifies its use. The method should return IAsyncEnumerable of items being streamed from the gRPC server. I have a specified timeout for the streaming not to exceed. If the timeout occurs, I…
mnj
  • 2,539
  • 3
  • 29
  • 58
1
vote
1 answer

EF Core long running streaming query with IAsyncEnumerable throws exception

I'm writing vary large tables to CSV files using IAsyncEnumerable to stream the rows from the database to my application, doing some modifications and then writing them into a CSV file stream. The tables contain a lot of rows, so the queries are…
wertzui
  • 5,148
  • 3
  • 31
  • 51
1
vote
2 answers

Conform IAsyncEnumerable to Dataflow ISourceBlock

I have an existing transformation function Func, IAsyncEnumerable> that I want to use inside a Dataflow pipeline. In order to link this transformation function, I need the input side of this function to map to…
Bouke
  • 11,768
  • 7
  • 68
  • 102