Skip to content

Commit

Permalink
Merge pull request #368 from dariogriffo/PostProcessorCancellationToken
Browse files Browse the repository at this point in the history
Add CancellationToken to IRequestPostProcessor
  • Loading branch information
jbogard committed Feb 26, 2019
2 parents 94b83c1 + 8e35024 commit 8e0c349
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<PropertyGroup>
<Authors>Jimmy Bogard</Authors>
<LangVersion>latest</LangVersion>
<VersionPrefix>6.1.0</VersionPrefix>
<VersionPrefix>7.0.0</VersionPrefix>
</PropertyGroup>
</Project>
3 changes: 2 additions & 1 deletion samples/MediatR.Examples/ConstrainedRequestPostProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediatR.Pipeline;

Expand All @@ -15,7 +16,7 @@ public ConstrainedRequestPostProcessor(TextWriter writer)
_writer = writer;
}

public Task Process(TRequest request, TResponse response)
public Task Process(TRequest request, TResponse response, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("- All Done with Ping");
}
Expand Down
3 changes: 2 additions & 1 deletion samples/MediatR.Examples/GenericRequestPostProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediatR.Pipeline;

Expand All @@ -13,7 +14,7 @@ public GenericRequestPostProcessor(TextWriter writer)
_writer = writer;
}

public Task Process(TRequest request, TResponse response)
public Task Process(TRequest request, TResponse response, CancellationToken cancellationToken)
{
return _writer.WriteLineAsync("- All Done");
}
Expand Down
6 changes: 4 additions & 2 deletions src/MediatR/Pipeline/IRequestPostProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace MediatR.Pipeline
namespace MediatR.Pipeline
{
using System.Threading;
using System.Threading.Tasks;

/// <summary>
Expand All @@ -14,7 +15,8 @@ public interface IRequestPostProcessor<in TRequest, in TResponse>
/// </summary>
/// <param name="request">Request instance</param>
/// <param name="response">Response instance</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>An awaitable task</returns>
Task Process(TRequest request, TResponse response);
Task Process(TRequest request, TResponse response, CancellationToken cancellationToken);
}
}
2 changes: 1 addition & 1 deletion src/MediatR/Pipeline/RequestPostProcessorBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<TResponse> Handle(TRequest request, CancellationToken cancella

foreach (var processor in _postProcessors)
{
await processor.Process(request, response).ConfigureAwait(false);
await processor.Process(request, response, cancellationToken).ConfigureAwait(false);
}

return response;
Expand Down
2 changes: 1 addition & 1 deletion test/MediatR.Tests/Pipeline/RequestPostProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Task<Pong> Handle(Ping request, CancellationToken cancellationToken)

public class PingPongPostProcessor : IRequestPostProcessor<Ping, Pong>
{
public Task Process(Ping request, Pong response)
public Task Process(Ping request, Pong response, CancellationToken cancellationToken)
{
response.Message = response.Message + " " + request.Message;

Expand Down

0 comments on commit 8e0c349

Please sign in to comment.