loading...
Cover image for What's the big deal with IAsyncEnumerable in .NET Core 3.0?

What's the big deal with IAsyncEnumerable<T> in .NET Core 3.0?

Anthony Chu on July 31, 2019

One of the most exciting features of .NET Core 3.0 and C# 8.0 has been the addition of IAsyncEnumerable&lt;T&gt; (aka async streams). But what's so...
pic
Editor guide
Collapse
saint4eva profile image
saint4eva

This is cool. Can you write something about SignalR? Thank you.

Collapse
anthony profile image
Anthony Chu Author

Sure. Anything in particular that you want to read about?

Collapse
dr_dimaka profile image
Dmitry Pavlov

I would love to read about a current state of SignalR / SSE (Server Sent Events) / gRPC / anything else? - features, gaps, areas to apply/consider using for. What is implemented / supported in .NET Core 3 for "realtime" like apps.

Collapse
saint4eva profile image
saint4eva

The use of IAsyncEnumerable in a SignalR application. Especially regarding clients communicating to each other. Thank you

Collapse
hte305 profile image
Ha Tuan Em

It's great. I love SignalR!!

Collapse
maajidqureshi profile image
Majid Qureshi

I would love to read about singalR

Collapse
mohan5k profile image
MohanMaladi

Is there any way that u can show with stopwatch or with memory consumption matching, showing old vs new way is much efficient?

Collapse
carstenk_dev profile image
Carsten

I don't think it will be more efficient in that sense - it blocks less threads so your server can scale better (await more IO bound operations like the DB calls here)

If you use this for algorithms (CPU bound operations) the runtime will probably be worse (there surely is even more overhead than the one produced by async/awaits state machines)

Collapse
artour profile image
ar-tour

Do you know how does it work under the hood? I mean, in your example you pass query like select * from... but, since it's lazy loaded, what's the actual query executed?
How I see it is it retrieves records one by one, which is something similar to looping through IQueryable.
Am I wrong? If so, how does it work exactly?

Collapse
slavius profile image
Slavius

I don't know exactly how this works with other DB servers but MSSQL uses so called TDS (Tabular Data Stream) protocol to deliver results which is a stream of data rows. This allows asynchronous stream processing within .Net Core applications leveraging IAsyncEnumerable<>.

Collapse
emmettchildress profile image
emmett childress jr

Can you provide an F# example? I've been looking for a way to return an asynSeq.

Collapse
candidodmv profile image
Vinicius Dutra

That's awesome! Thanks for sharing!

Collapse
fisseha76056312 profile image
Fisseha

I'm new to this whole progg. stuff but I know there isn't no one out there better than Microsoft. Go .NET !!! hope I get to use this new feature one day

again GO GO .NET

Collapse
techwatching profile image
Alexandre

Nice article, thanks. A thing I wonder when you are using IAsyncEnumerable in controller as you return type of a route. How do you handle the cas where you want to return a NotFoundResult when no items are in the IAsyncEnumerable.

Collapse
kralizek profile image
Renato Golia

Does the new interface support on demand pull?

I.e. what happens if the table contains 100 records but the client uses Take(15)?

Collapse
tyrrrz profile image
Alexey Golub

I.e. what happens if the table contains 100 records but the client uses Take(15)?

The MoveNextAsync method is called 15 times. Wether or not it does something is an implementation detail.

Collapse
hte305 profile image
Ha Tuan Em

This article very nice. Useful and easy for understand ! Thank Chu !

Collapse
mecitsemerci profile image
Mecit Semerci

That's great! It's very helpful. Thanks for sharing.