Build with an Azure free account. Get USD200 credit for 30 days and 12 months of free services.

Start free today

Supporting IAsyncEnumerable with LINQ

Play Supporting IAsyncEnumerable with LINQ
Sign in to queue

Description

With IAsyncEnumerable being introduced in .NET Core 3, it's not surprising that developers might want to leverage their existing knowledge of Linq operations when working with async streams.

In this episode, Bart De Smet comes on to talk about the System.Linq.Async nuget package that adds some common Linq query operators to IAsyncEnumerable.

  • [01:15] - What's the history behind IAsyncEnumerable?
  • [02:17] - How does the new IAsyncEnumerable compare to the previous?
  • [03:39] - Can IAsyncEnumerable scale to large systems?
  • [06:15] - How do the ways we partition work with IAsyncEnumerable differ from IEnumerable?
  • [08:34] - What can we make use of IAsyncEnumerable? (Demo)
  • [13:03] - How can we add support for common Linq expressions to IAsyncEnumerable?
  • [16:11] - How do filtering and ordering operations work with IAsyncEnumerable?
  • [20:00] - How important was community support to the longevity of this project?
  • [21:55] - How have the language features made code much simpler?

 

Useful Links

 

Embed

Download

The Discussion

  • User profile image
    Mass23g
    [16:41](https://channel9.msdn.com/Shows/On-NET/Supporting-IAsyncEnumerable-with-LINQ#time=16m41s) when talking about the Linq in the code, shouldn't `where` as well cause the query to get the whole thing for filtering?
  • User profile image
    wkempf
    @Mass23g, no, Where only requires a single item to process and possibly produce a new item. OrderBy is different. Given one item from the total collection you cannot yet produce an item, because to produce an item in sorted order you have to have the entire collection to know what item is next.
  • User profile image
    wkempf
    Let's give an analogy to make this a bit clearer. Imagine there's 3 people, Joe, Kelly and Brian. Brian has a bunch of numbered balls. Joe wants only even numbered balls and asks Kelly to get those from Brian (Kelly represents the Where clause here). Kelly can take a ball from Brian determine if it's even or not, and either throw it away or give it to Joe. She can do this without having to take all of the balls from Brian.

    Conversely, say that Joe wants the balls sorted by that number. Kelly can take a ball from Brian, but she can't yet give it to Joe, because she doesn't know if that ball is the next ball to give Joe or not yet. She can't know until she gets all the balls from Brian and sorts them first.

    Most of the LINQ operators do not require consuming the full source collection first before producing an item. Even something like Distinct can process an item at a time. Back to the people example, to produce distinctly numbered balls all Kelly has to do is keep track of numbers she's seen. When she gets a ball from Brian she checks to see if it's a number she's seen before. If it is, she throws the ball away. If it's not, she records the number and gives the ball to Joe. No need to take all the balls from Brian first.
  • User profile image
    Mass23g
    @wkempf your statement is correct. Maybe I didn't describe my question correctly. Yes, `Where` takes one item every time. But it will have to look through all items in the sequence to get the *correct* result for output. Actually it's the same point.
    In your example, Kelly must first look through all balls to get the even number balls, Then sorted them and feedback.

Add Your 2 Cents