/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/core/extensions/snippets/channels/Program.Consumer.cs
41 строка
1 KB
David Pine
`System.Threading.Channels` in .NET (#30462)
04 авг 2022, 17:10
Не верифицирован
04 авг 2022, 17:10
27db9b4
Код
Авторство
О чём код?
internal static partial class Program { // <awaitforeach> static async ValueTask ConsumeWithAwaitForeachAsync( ChannelReader<Coordinates> reader) { await foreach (Coordinates coordinates in reader.ReadAllAsync()) { Console.WriteLine(coordinates); } } // </awaitforeach> // <whiletrue> static async ValueTask ConsumeWithWhileAsync( ChannelReader<Coordinates> reader) { while (true) { // May throw ChannelClosedException if // the parent channel's writer signals complete. Coordinates coordinates = await reader.ReadAsync(); Console.WriteLine(coordinates); } } // </whiletrue> // <nestedwhile> static async ValueTask ConsumeWithNestedWhileAsync( ChannelReader<Coordinates> reader) { while (await reader.WaitToReadAsync()) { while (reader.TryRead(out Coordinates coordinates)) { Console.WriteLine(coordinates); } } } // </nestedwhile> }