Skip to content

Commit

Permalink
feat: set ConfigureAwait(false) on the delegate task
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Oct 29, 2023
1 parent bc76194 commit a95a91e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/Prism.Core/Commands/AsyncDelegateCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq.Expressions;
using System.Linq.Expressions;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -86,17 +86,19 @@ public bool IsExecuting
///<summary>
/// Executes the command.
///</summary>
public async Task Execute(CancellationToken cancellationToken = default)
public async Task Execute(CancellationToken? cancellationToken)
{
var token = cancellationToken ?? _getCancellationToken();
try
{
if (!_enableParallelExecution && IsExecuting)
return;

IsExecuting = true;
await _executeMethod(cancellationToken);
await _executeMethod(token)
.ConfigureAwait(false);
}
catch (TaskCanceledException) when (cancellationToken.IsCancellationRequested)
catch (TaskCanceledException) when (token.IsCancellationRequested)
{
// Do nothing... the Task was cancelled
}
Expand Down
11 changes: 7 additions & 4 deletions src/Prism.Core/Commands/AsyncDelegateCommand{T}.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq.Expressions;
using System.Linq.Expressions;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -88,17 +88,20 @@ public bool IsExecuting
///<summary>
/// Executes the command.
///</summary>
public async Task Execute(T parameter, CancellationToken cancellationToken = default)
public async Task Execute(T parameter, CancellationToken? cancellationToken)
{
var token = cancellationToken ?? _getCancellationToken();

try
{
if (!_enableParallelExecution && IsExecuting)
return;

IsExecuting = true;
await _executeMethod(parameter, cancellationToken);
await _executeMethod(parameter, token)
.ConfigureAwait(false);
}
catch (TaskCanceledException) when (cancellationToken.IsCancellationRequested)
catch (TaskCanceledException) when (token.IsCancellationRequested)
{
// Do nothing... the Task was cancelled
}
Expand Down

0 comments on commit a95a91e

Please sign in to comment.