Skip to content

Commit

Permalink
use ContinueWith rather than finally for coroutine result types
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS committed Jul 23, 2024
1 parent 8d1cd07 commit 9210fbd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/PowerShell/CommonFiles/PowerShellCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ internal Task RunOnMTA(Func<Task> func)
this.Write(StreamType.Verbose, "Already running on MTA");
try
{
return func();
Task result = func();
result.ContinueWith((task) => this.Complete(), TaskContinuationOptions.ExecuteSynchronously);
return result;
}
finally
catch
{
this.Complete();
throw;
}
}

Expand Down Expand Up @@ -150,11 +153,14 @@ internal Task<TResult> RunOnMTA<TResult>(Func<Task<TResult>> func)
this.Write(StreamType.Verbose, "Already running on MTA");
try
{
return func();
Task<TResult> result = func();
result.ContinueWith((task) => this.Complete(), TaskContinuationOptions.ExecuteSynchronously);
return result;
}
finally
catch
{
this.Complete();
throw;
}
}

Expand Down

0 comments on commit 9210fbd

Please sign in to comment.