Lazy create ResourceInvoker.InvokeAlwaysRunResultFilters statemachine

This commit is contained in:
Ben Adams 2019-04-12 03:05:42 +01:00 committed by Ryan Nowak
parent 6039699afa
commit 0657a3ed1a
1 changed files with 33 additions and 8 deletions

View File

@ -1011,7 +1011,9 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
} }
} }
private async Task InvokeAlwaysRunResultFilters() private Task InvokeAlwaysRunResultFilters()
{
try
{ {
var next = State.ResultBegin; var next = State.ResultBegin;
var scope = Scope.Invoker; var scope = Scope.Invoker;
@ -1020,7 +1022,30 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
while (!isCompleted) while (!isCompleted)
{ {
await ResultNext<IAlwaysRunResultFilter, IAsyncAlwaysRunResultFilter>(ref next, ref scope, ref state, ref isCompleted); var lastTask = ResultNext<IAlwaysRunResultFilter, IAsyncAlwaysRunResultFilter>(ref next, ref scope, ref state, ref isCompleted);
if (!lastTask.IsCompletedSuccessfully)
{
return Awaited(this, lastTask, next, scope, state, isCompleted);
}
}
return Task.CompletedTask;
}
catch (Exception ex)
{
// Wrap non task-wrapped exceptions in a Task,
// as this isn't done automatically since the method is not async.
return Task.FromException(ex);
}
static async Task Awaited(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
{
await lastTask;
while (!isCompleted)
{
await invoker.ResultNext<IAlwaysRunResultFilter, IAsyncAlwaysRunResultFilter>(ref next, ref scope, ref state, ref isCompleted);
}
} }
} }