Skip to content

Commit

Permalink
Lazy create ResourceInvoker.InvokeAlwaysRunResultFilters statemachine
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored and rynowak committed Apr 15, 2019
1 parent 6039699 commit 0657a3e
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,16 +1011,41 @@ static async Task Awaited(ResourceInvoker invoker, Task lastTask, State next, Sc
}
}

private async Task InvokeAlwaysRunResultFilters()
private Task InvokeAlwaysRunResultFilters()
{
var next = State.ResultBegin;
var scope = Scope.Invoker;
var state = (object)null;
var isCompleted = false;
try
{
var next = State.ResultBegin;
var scope = Scope.Invoker;
var state = (object)null;
var isCompleted = false;

while (!isCompleted)
while (!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 ResultNext<IAlwaysRunResultFilter, IAsyncAlwaysRunResultFilter>(ref next, ref scope, ref state, ref isCompleted);
await lastTask;

while (!isCompleted)
{
await invoker.ResultNext<IAlwaysRunResultFilter, IAsyncAlwaysRunResultFilter>(ref next, ref scope, ref state, ref isCompleted);
}
}
}

Expand Down

0 comments on commit 0657a3e

Please sign in to comment.