Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is IAsyncEnumerable supported in C# 8.0?

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:

enter image description here

like image 271
maksymiuk Avatar asked Apr 24 '19 02:04

maksymiuk


People also ask

What is IAsyncEnumerable C#?

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.

Is foreach Async in C#?

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.

What is ValueTask C#?

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.

Is yield return Async?

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.


1 Answers

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

like image 73
TheGeneral Avatar answered Sep 24 '22 01:09

TheGeneral