CompletedTask<T, TConstant>
Represents cache of completed tasks.
using DotNext.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace DotNext.Threading.Tasks
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public static class CompletedTask<[System.Runtime.CompilerServices.Nullable(2)] T, [System.Runtime.CompilerServices.Nullable(0)] TConstant> where TConstant : Constant<T>, new
{
private static readonly T Value = (Constant<T>)new TConstant();
public static readonly Task<T> Task = System.Threading.Tasks.Task.FromResult<T>(Value);
internal static T WhenFaulted(Task<T> task)
{
if (!task.IsFaulted)
return task.Result;
return Value;
}
internal static T WhenCanceled(Task<T> task)
{
if (!task.IsCanceled)
return task.Result;
return Value;
}
internal static T WhenFaultedOrCanceled(Task<T> task)
{
if (!(task.IsFaulted | task.IsCanceled))
return task.Result;
return Value;
}
}
}