-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from IharBury/exception-handler-cancellation
Dispatcher supports exception handler cancellation and success handling
- Loading branch information
Showing
8 changed files
with
689 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,4 +178,7 @@ Artifacts/** | |
# Cake related | ||
Build/** | ||
!Build/packages.config | ||
Tools/** | ||
Tools/** | ||
|
||
# Visual Studio | ||
.vs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Threading; | ||
|
||
namespace LiquidProjections.Abstractions | ||
{ | ||
public class SubscriptionInfo | ||
{ | ||
public string Id { get; set; } | ||
|
||
public IDisposable Subscription { get; set; } | ||
|
||
/// <summary> | ||
/// The cancellation is requested when the subscription is being cancelled. | ||
/// The cancellation token is disposed and cannot be used after the subscription cancellation is completed. | ||
/// Old versions of event stores do not have the cancellation token. | ||
/// </summary> | ||
public CancellationToken? CancellationToken { get; set; } | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace LiquidProjections.Testing | ||
{ | ||
internal static class TaskExtensions | ||
{ | ||
public static Task WithWaitCancellation(this Task task, CancellationToken cancellationToken) | ||
{ | ||
var taskCompletionSource = new TaskCompletionSource<bool>(); | ||
CancellationTokenRegistration registration = cancellationToken.Register(CancelTask, taskCompletionSource); | ||
|
||
task.ContinueWith(ContinueTask, Tuple.Create(taskCompletionSource, registration), CancellationToken.None, | ||
TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); | ||
|
||
return taskCompletionSource.Task; | ||
} | ||
|
||
private static void CancelTask(object state) | ||
{ | ||
var taskCompletionSource = (TaskCompletionSource<bool>)state; | ||
taskCompletionSource.TrySetCanceled(); | ||
} | ||
|
||
private static void ContinueTask(Task task, object state) | ||
{ | ||
var tcsAndRegistration = (Tuple<TaskCompletionSource<bool>, CancellationTokenRegistration>)state; | ||
|
||
if (task.IsFaulted && (task.Exception != null)) | ||
{ | ||
tcsAndRegistration.Item1.TrySetException(task.Exception.InnerException); | ||
} | ||
|
||
if (task.IsCanceled) | ||
{ | ||
tcsAndRegistration.Item1.TrySetCanceled(); | ||
} | ||
|
||
if (task.IsCompleted) | ||
{ | ||
tcsAndRegistration.Item1.TrySetResult(false); | ||
} | ||
|
||
tcsAndRegistration.Item2.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters