C# 8.0 features – Async streams

Async Streams

Async/await pattern in C# 5.0 return single value. With C# 8.0, we can have async method return a stream of values.

If GenerateRandom is a an async method that returns multiple values through yield statement, we can iterate through await foreach command.

await foreach (var number in GenerateRandom())
{
    Console.WriteLine(number);
}

Reference
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#asynchronous-streams