// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading; using System.Threading.Tasks; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public static class TaskUtilities { #if DOTNET5_4 public static Task CompletedTask = Task.CompletedTask; #else public static Task CompletedTask = Task.FromResult(null); #endif public static Task ZeroTask = Task.FromResult(0); public static Task GetCancelledTask(CancellationToken cancellationToken) { #if DOTNET5_4 return Task.FromCanceled(cancellationToken); #else var tcs = new TaskCompletionSource(); tcs.TrySetCanceled(); return tcs.Task; #endif } public static Task GetCancelledZeroTask() { // Task.FromCanceled doesn't return Task var tcs = new TaskCompletionSource(); tcs.TrySetCanceled(); return tcs.Task; } } }