/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/core/extensions/snippets/channels/Program.cs
35 строк
1 KB
Nick Schonning
fix: various typos outside samples/ (#32862)
05 дек 2022, 19:37
Не верифицирован
05 дек 2022, 19:37
d1c3f9f
Код
Авторство
О чём код?
bool isBounded = true; Channel<Coordinates> gps = isBounded ? CreateBounded() : CreateUnbounded(); string producer = args?.Length > 0 ? args[0] : "whilewrite"; Func<ChannelWriter<Coordinates>, Coordinates, ValueTask> produceCoordinatesAsync = producer switch { "whilewrite" => ProduceWithWhileWriteAsync, "waittowrite" => ProduceWithWaitToWriteAsync, _ => ProduceWithWhileWriteAsync }; string consumer = args?.Length > 1 ? args[1] : "nestedwhile"; Func<ChannelReader<Coordinates>, ValueTask> consumeCoordinatesAsync = consumer switch { "nestedwhile" => ConsumeWithNestedWhileAsync, "awaitforeach" => ConsumeWithAwaitForeachAsync, "whiletrue" => ConsumeWithWhileAsync, _ => ConsumeWithAwaitForeachAsync }; Coordinates initialCoordinates = new( DeviceId: Guid.NewGuid(), Latitude: -90, Longitude: -180); using (LoggingStopwatch.WriteDurationToConsole()) { await Task.WhenAll( produceCoordinatesAsync(gps.Writer, initialCoordinates).AsTask(), consumeCoordinatesAsync(gps.Reader).AsTask()); }