/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/SignalR/common/testassets/Tests.Utils/TaskExtensions.cs
35 строк
1 KB
Pranav K
Use file scoped namespaces (#38076)
06 ноя 2021, 03:52
Не верифицирован
06 ноя 2021, 03:52
a450cb6
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace System.Threading.Tasks; #if TESTUTILS public #else internal #endif static class TaskExtensions { public static async Task OrThrowIfOtherFails(this Task task, Task otherTask) { var completed = await Task.WhenAny(task, otherTask); if (completed == otherTask && otherTask.IsFaulted) { // Manifest the exception otherTask.GetAwaiter().GetResult(); throw new Exception("Unreachable code"); } else { // Await the task we were asked to await. Either it's finished, or the otherTask finished successfully, and it's not our job to check that await task; } } public static async Task<T> OrThrowIfOtherFails<T>(this Task<T> task, Task otherTask) { await OrThrowIfOtherFails((Task)task, otherTask); // If we get here, 'task' is finished and succeeded. return task.GetAwaiter().GetResult(); } }