Refactor TreeMatcher to not use async (#552)

This commit is contained in:
James Newton-King 2018-06-13 08:48:27 +12:00 committed by GitHub
parent 28d1bc4fa2
commit 6a6bd3f0da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 17 deletions

View File

@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers
_cache.EnsureInitialized();
}
public override async Task MatchAsync(HttpContext httpContext, IEndpointFeature feature)
public override Task MatchAsync(HttpContext httpContext, IEndpointFeature feature)
{
if (httpContext == null)
{
@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers
continue;
}
await SelectEndpointAsync(httpContext, feature, (MatcherEndpoint[])entry.Tag);
SelectEndpoint(httpContext, feature, (MatcherEndpoint[])entry.Tag);
if (feature.Endpoint != null)
{
@ -109,11 +109,15 @@ namespace Microsoft.AspNetCore.Routing.Matchers
}
}
return;
// Found a matching endpoint
return Task.CompletedTask;
}
}
}
}
// No match found
return Task.CompletedTask;
}
private bool MatchConstraints(
@ -139,19 +143,9 @@ namespace Microsoft.AspNetCore.Routing.Matchers
return true;
}
private Task SelectEndpointAsync(HttpContext httpContext, IEndpointFeature feature, IReadOnlyList<MatcherEndpoint> endpoints)
private void SelectEndpoint(HttpContext httpContext, IEndpointFeature feature, IReadOnlyList<MatcherEndpoint> endpoints)
{
MatcherEndpoint endpoint;
try
{
endpoint = (MatcherEndpoint)_endpointSelector.SelectBestCandidate(httpContext, endpoints);
}
catch (Exception ex)
{
// Handle AmbiguousMatchException from EndpointSelector
return Task.FromException(ex);
}
var endpoint = (MatcherEndpoint)_endpointSelector.SelectBestCandidate(httpContext, endpoints);
if (endpoint == null)
{
@ -164,8 +158,6 @@ namespace Microsoft.AspNetCore.Routing.Matchers
feature.Endpoint = endpoint;
feature.Invoker = endpoint.Invoker;
}
return Task.CompletedTask;
}
private UrlMatchingTree[] CreateTrees(IReadOnlyList<Endpoint> endpoints)