Its really hard to find any information on IAsyncEnumerable
, other than a few mentions in the 'What's New c# 8.0' articles. Trying to use it in Visual Studio 2019 with netstandard 2.0 and C# 8 enabled, it does recognize the class but i get a ton of errors on build:
IAsyncEnumerable<T> exposes an enumerator that has a MoveNextAsync() method that can be awaited. This means a method that produces this result can make asynchronous calls in between yielding results.
Foreach itself is very useful and efficient for most operations. Sometimes special situations arise where high latency in getting data to iterate over, or processing data inside the foreach depends on an operation with very high latency or long processing.
From the time the Task Parallel Library (TPL) was introduced, developers have been using the Task class to write asynchronous code. The ValueTask struct is a new type introduced in C# 7.0 that provides a way to work with time-sensitive tasks with less resource consumption (memory, CPU, etc.) overhead.
Using an async yield return statement requires that the method be asynchronous, making use of async/await. Usually an async method will return a task. Your first thought when using yield return in your async method may be to have the method return Task of IEnumerable.
C# 8 supports these features. However, this wont work with .Net standard 2.0
IAsyncEnumerable Interface
Applies to
.NET Core 3.0 Preview 3
.NET Standard 2.1 Preview
You will have to get either one of the previews.
You can find more information on .Net Core 3 Preview here
https://devblogs.microsoft.com/dotnet/announcing-net-core-3-preview-4/
https://dotnet.microsoft.com/download/dotnet-core/3.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With