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

System.InvalidOperationException when using GetAwaiter().GetResult() with ServiceBusReceiver.PeekMessagesAsync

Context We are using GetAwaiter().GetResult() because PowerShell's Cmdlet.ProcessRecord() does not support async/await. Code Sample class Program { static async Task Main(string[] args) { var topicPath = "some-topic"; var…
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
3
votes
1 answer

Processing a Stream into IAsyncEnumerable - Stream is not readable

I have a workflow where I try to do the following: A method accepting a callback, which internally produces a Stream and the callers of that method can use the callback to process the Stream whichever way they want In one particular case, the…
zidour
  • 83
  • 4
3
votes
1 answer

How to validate arguments for IAsyncEnumerable returning method before actual iteration takes place?

I have a simple scenario where I have a class with the following method: public async IAsyncEnumerable GetEntities(IQueryOptions options){ if(!validator.ValidateQuery(options)) { throw new ArgumentException(nameof(options));} var data =…
Michael P
  • 670
  • 7
  • 23
3
votes
1 answer

IAsyncEnumerable does not contain a definition for 'GetAwaiter' in ADO.NET

This code in .Net Core 3.1, C# 8: await dB.GetListAsync(); results in this error : IAsyncEnumerable does not contain a definition for 'GetAwaiter' The answer provided here : https://stackoverflow.com/a/60148747/4180382 didn't help…
Ole EH Dufour
  • 2,968
  • 4
  • 23
  • 48
3
votes
2 answers

How to aggregate results of an IAsyncEnumerable

I want to ask if there is a plan or exists a method to aggregate the return(s) of an IAsyncEnumerable? So given the below method why is there no terse way to aggregate its result? public async IAsyncEnumerable GenerateAsyncEnumerable(int…
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152
3
votes
1 answer

How to await the results of an IAsyncEnumerable>, with a specific level of concurrency

I have an asynchronous stream of tasks, that is generated by applying an async lambda to a stream of items: IAsyncEnumerable streamOfItems = AsyncEnumerable.Range(1, 10); IAsyncEnumerable> streamOfTasks = streamOfItems.Select(async…
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
3
votes
1 answer

Correct disposal in IAsyncEnumerable methods?

The answer to this may be that it's not possible, but the question is: assume you have a C# method for consuming the lines in a TextReader that returns IAsyncEnumerable. How do you ensure that when DisposeAsync is called on the…
Julian Birch
  • 2,605
  • 1
  • 21
  • 36
3
votes
1 answer

How to break out of an IAsyncEnumerable when iterating?

C# 8 adds support for asynchronuous iterator blocks, so you can await things and return an IAsyncEnumarator instead of an IEnumerable: public async IAsyncEnumerable EnumerateAsync() { for (int i = 0; i < 10; i++) { yield return i; …
Bruno Zell
  • 7,761
  • 5
  • 38
  • 46
2
votes
1 answer

Consuming an IAsyncEnumerable that makes an async call to another service or API and the response returns in batches

I am trying to create an API that returns a result as soon as it is ready. The goal is: An API endpoint that yields a result as soon as it is ready A consuming app that calls the endpoint and process the data as soon as it is ready My API calls…
von v.
  • 16,868
  • 4
  • 60
  • 84
2
votes
2 answers

When to convert IEnumerable to IAsyncEnumerable

In the .NET documentation for Controller Action Return Types (doc link), it shows this example on how to return a async response stream: [HttpGet("asyncsale")] public async IAsyncEnumerable GetOnSaleProductsAsync() { var products =…
roverred
  • 1,841
  • 5
  • 29
  • 46
2
votes
1 answer

ASP.NET Core 7 valditate IAsyncEnumerable against data annotation

How to perform a data annotation validation for the input as IAsyncEnumerable in ASP.NET Core 7 API controller POST action. I tried to use the following code, but validation didn't occur. public record struct…
2
votes
0 answers

Is there a way for get NSwag Swagger to generate a client that can consume IAsyncEnumerable endpoint?

I have an endpoint that returns an IAsyncEnumerable [HttpPost("GetByDates")] [ProducesResponseType(typeof(IAsyncEnumerable), StatusCodes.Status200OK)] public async IAsyncEnumerable GetByDates([FromBody] DayModelGetByDatesRequest…
Olaf Dlugosz
  • 81
  • 1
  • 4
2
votes
2 answers

How to handle errors in method that has IAsyncEnumerable as return type

I have an API endpoint: [HttpGet("api/query")] public async IAsyncEnumerable Query(string name) { await foreach(var item in _myService.CallSomethingReturningAsyncStream(name)) { yield return item; } } I would like to be…
Dušan
  • 269
  • 1
  • 11
2
votes
1 answer

Asp.Net Core API Controller method returning IAsyncEnumerable not producing the intended behavior

I have an API Controller setup which return 277,000+ items: [HttpPost] public async IAsyncEnumerable GetLocations([FromBody] LocationReportQueryDto locationReportQuery, CancellationToken token = default) { var result = await…
2
votes
1 answer

Calling IAsyncEnumerable before other methods

Good day guys, Please I'm trying to read all file paths in a folder using IAsyncEnumerable, based on a library that I'm using. I've been able to create a method for that, but the challenge I have is that, the library…
Timothy Ayodele
  • 185
  • 1
  • 1
  • 9