<PackageReference Include="Polly.Core" Version="8.4.2" />

TaskHelper

static class TaskHelper
using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Polly.Utils { internal static class TaskHelper { public static void GetResult([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] this ValueTask<VoidResult> task) { if (task.IsCompleted) { VoidResult result = task.Result; } else task.Preserve().GetAwaiter().GetResult(); } [System.Runtime.CompilerServices.NullableContext(1)] public static TResult GetResult<[System.Runtime.CompilerServices.Nullable(2)] TResult>([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] this ValueTask<TResult> task) { if (task.IsCompleted) return task.Result; return task.Preserve().GetAwaiter().GetResult(); } } }