From ecee8433a0618064b200fd4146f5450bf89ca8d1 Mon Sep 17 00:00:00 2001 From: Alex Macocian Date: Fri, 18 Oct 2024 13:18:45 +0200 Subject: [PATCH] Cast async Tasks to Delegate and let the framework handle awaiting it --- .../Net.Sdk.Web.Extensions.SourceGenerators.csproj | 2 +- .../UseRoutesGenerator.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Net.Sdk.Web.Extensions.SourceGenerators/Net.Sdk.Web.Extensions.SourceGenerators.csproj b/Net.Sdk.Web.Extensions.SourceGenerators/Net.Sdk.Web.Extensions.SourceGenerators.csproj index 12251fe..fe9268a 100644 --- a/Net.Sdk.Web.Extensions.SourceGenerators/Net.Sdk.Web.Extensions.SourceGenerators.csproj +++ b/Net.Sdk.Web.Extensions.SourceGenerators/Net.Sdk.Web.Extensions.SourceGenerators.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 0.8.17 + 0.8.18 latest true Alexandru Macocian diff --git a/Net.Sdk.Web.Extensions.SourceGenerators/UseRoutesGenerator.cs b/Net.Sdk.Web.Extensions.SourceGenerators/UseRoutesGenerator.cs index e94620e..972a0d9 100644 --- a/Net.Sdk.Web.Extensions.SourceGenerators/UseRoutesGenerator.cs +++ b/Net.Sdk.Web.Extensions.SourceGenerators/UseRoutesGenerator.cs @@ -262,11 +262,11 @@ public class UseRoutesGenerator : IIncrementalGenerator return returnTypeSymbol?.ToDisplayString() switch { "System.Threading.Tasks.Task" => @$" - builder.Map{type}(""{pattern}"", async (HttpContext httpContext, {classDeclarationSyntax.Identifier} route{(parameters.Length > 0 ? $", {parameters}" : "")}) => + builder.Map{type}(""{pattern}"", (Delegate)((HttpContext httpContext, {classDeclarationSyntax.Identifier} route{(parameters.Length > 0 ? $", {parameters}" : "")}) => {{ var cancellationToken = httpContext.RequestAborted; - return await route.{methodDeclarationSyntax.Identifier}({variables}); - }}){routeFilterSb};", + return route.{methodDeclarationSyntax.Identifier}({variables}); + }})){routeFilterSb};", "Microsoft.AspNetCore.Http.IResult" => @$" builder.Map{type}(""{pattern}"", (HttpContext httpContext, {classDeclarationSyntax.Identifier} route{(parameters.Length > 0 ? $", {parameters}" : "")}) => {{