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

ASP.NET Core stream an IAsyncEnumerate on nested property

I have read about returning an IAsyncEnumerate to take advantage of HTTP streaming. This works if I return an IAsyncEnumerate as top level. so, in the client: Stream responseStream = await…
GLuca74
  • 105
  • 6
2
votes
2 answers

Unordered F# AsyncSeq.mapParallel with throttling

I'm using F# and have an AsyncSeq>. Each item will take a varying amount of time to process and does I/O that's rate-limited. I want to run all the operations in parallel and then pass them down the chain as an AsyncSeq<'t> so I can…
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
2
votes
1 answer

EF core ToAsyncEnumerable and AsAsyncEnumerable ends with System.ObjectDisposedException

I'm working on xamarin project and using Entity Framework Core to access database. I know it's not a good solution but i decided to do it without application server. The DAL layer is using repository pattern and BL layer is using facade pattern with…
2
votes
1 answer

How to Zip concurrently two IAsyncEnumerables?

I have two asynchronous sequences that I want to "zip" in pairs, and for this purpose I used the Zip operator from the System.Linq.Async package. This operator behaves in an undesirable way though, at least for my case. Instead of enumerating the…
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
2
votes
1 answer

ASP.NET 6 - Asynchronous serialization of IAsyncEnumerable class property

ASP.NET Core now supports async streaming from controller actions all the way down to the response JSON formatter. Returning an IAsyncEnumerable from an action no longer buffers the response content in memory before it gets sent. This helps reduce…
Rafi Henig
  • 5,950
  • 2
  • 16
  • 36
2
votes
1 answer

Should IAsyncEnumerator.DisposeAsync() throw if the last MoveNextAsync() task is not awaited?

Why does the UseEventsFail throw in the code below? Could it be that I dispose the async enumerator without awaiting the last MoveNextAsync() task? This example is simplified repro of my real program, so I need to dispose the async enumerator to…
maloo
  • 685
  • 1
  • 6
  • 16
2
votes
2 answers

IAsyncEnumerable for never ending stream

I am building a client for continuously consuming new records from a data source. The integration is pull-based and my client periodically queries the data source for new records. I'm using IAsyncEnumerable as a return type for this continuous…
2
votes
1 answer

SqlBulkCopy throws "Operation is not valid due to the current state of the object"

I'm attempting to create a custom DataReader for an IAsyncEnumerable collection in order to load the records into a database table via SqlBulkCopy. I'm following along the lines of the code example and solution outlined in this question - How to…
JamesEggers
  • 12,885
  • 14
  • 59
  • 86
2
votes
0 answers

Using IAsyncEnumerable as API output in ASP.NET Web API

The new IAsyncEnumerable interface is great, but is problematic when exposing data via an API. Taking the code from Anthony Chu's great post the endpoint works ... until you get to more than 8162 records ... IAsyncEnumerable's buffer limit. The…
Ruskin
  • 5,721
  • 4
  • 45
  • 62
2
votes
3 answers

How to enumerate an IAsyncEnumerable and invoke an async action for each element, allowing concurrency for each iteration/action pair?

I have an IAsyncEnumerable stream that contains data downloaded from the web, and I want to save asynchronously each piece of data in a SQL database. So I used the ForEachAwaitAsync extension method from the System.Linq.Async library. My…
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
2
votes
1 answer

What's the difference between IAsyncEnumerable and an iterator-generated IEnumerable>?

I'm trying to work out the advantage that IAsyncEnumerable brings over something like an IEnumerable>. I wrote the following class that allows me to wait for a sequence of numbers with a defined delay between each one: class…
Xenoprimate
  • 7,691
  • 15
  • 58
  • 95
2
votes
3 answers

How can I have an async stream return with 2 data sources

I have the following function that returns the standard output data, as an async stream, that results from running a System.Diagnostics.Process. Everything currently in the method works as intended; I can call it in an await foreach() loop and I get…
master_ruko
  • 629
  • 1
  • 4
  • 22
2
votes
1 answer

How to parallelize using IAsyncEnumerable

I have a situation where I am launching Task-s and I want their results to somehow be piped/enqueued in a datastructure as fast as possible, not caring on their order. Does IAsyncEnumerable fit for this situation? public async Task BigMethod() { …
2
votes
3 answers

How can I correctly use NpgsqlTransaction inside a IAsyncEnumerable emitter function?

I don't need to catch the exception, but I do need to Rollback if there is an exception: public async IAsyncEnumerable Select() { var t = await con.BeginTransactionAsync(token); try { var batchOfItems = new List();…
Kind Contributor
  • 17,547
  • 6
  • 53
  • 70
2
votes
1 answer

Is there a way to use System.Diagnostics.Process in an IAsyncEnumerator?

First off, I am targeting .Net Core 3.1 and C#8. I want something like this. public static async Task GetData() { var dataObj = new MyDataObj(); var args = ArgsHelperFunction(...); await foreach(string result in…
master_ruko
  • 629
  • 1
  • 4
  • 22