Lazy create ResourceInvoker.InvokeNextResourceFilterAwaitedAsync statemachine
This commit is contained in:
parent
cfc22fe0df
commit
70b02f8406
|
|
@ -890,13 +890,35 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ResourceExecutedContext> InvokeNextResourceFilterAwaitedAsync()
|
private Task<ResourceExecutedContext> InvokeNextResourceFilterAwaitedAsync()
|
||||||
{
|
{
|
||||||
Debug.Assert(_resourceExecutingContext != null);
|
Debug.Assert(_resourceExecutingContext != null);
|
||||||
|
|
||||||
if (_resourceExecutingContext.Result != null)
|
if (_resourceExecutingContext.Result != null)
|
||||||
{
|
{
|
||||||
// If we get here, it means that an async filter set a result AND called next(). This is forbidden.
|
// If we get here, it means that an async filter set a result AND called next(). This is forbidden.
|
||||||
|
return Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
var task = InvokeNextResourceFilter();
|
||||||
|
if (!task.IsCompletedSuccessfully)
|
||||||
|
{
|
||||||
|
return Awaited(this, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Assert(_resourceExecutedContext != null);
|
||||||
|
return Task.FromResult(_resourceExecutedContext);
|
||||||
|
|
||||||
|
static async Task<ResourceExecutedContext> Awaited(ResourceInvoker invoker, Task task)
|
||||||
|
{
|
||||||
|
await task;
|
||||||
|
|
||||||
|
Debug.Assert(invoker._resourceExecutedContext != null);
|
||||||
|
return invoker._resourceExecutedContext;
|
||||||
|
}
|
||||||
|
#pragma warning disable CS1998
|
||||||
|
static async Task<ResourceExecutedContext> Throw()
|
||||||
|
{
|
||||||
var message = Resources.FormatAsyncResourceFilter_InvalidShortCircuit(
|
var message = Resources.FormatAsyncResourceFilter_InvalidShortCircuit(
|
||||||
typeof(IAsyncResourceFilter).Name,
|
typeof(IAsyncResourceFilter).Name,
|
||||||
nameof(ResourceExecutingContext.Result),
|
nameof(ResourceExecutingContext.Result),
|
||||||
|
|
@ -904,11 +926,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
typeof(ResourceExecutionDelegate).Name);
|
typeof(ResourceExecutionDelegate).Name);
|
||||||
throw new InvalidOperationException(message);
|
throw new InvalidOperationException(message);
|
||||||
}
|
}
|
||||||
|
#pragma warning restore CS1998
|
||||||
await InvokeNextResourceFilter();
|
|
||||||
|
|
||||||
Debug.Assert(_resourceExecutedContext != null);
|
|
||||||
return _resourceExecutedContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task InvokeNextResourceFilter()
|
private Task InvokeNextResourceFilter()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue