Skip to content

Commit

Permalink
Pipe of Canceled Tasks (#5123)
Browse files Browse the repository at this point in the history
Canceled Task will have null as tresult.Exception.
The error handler need have a TaskCanceledException instance to indicate the cancellation.

Co-authored-by: Aaron Stannard <aaron@petabridge.com>
  • Loading branch information
Zetanova and Aaronontheweb committed Jul 8, 2021
1 parent 0b64872 commit 303d632
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/core/Akka/Actor/PipeToSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ public static Task PipeTo<T>(this Task<T> taskToPipe, ICanTell recipient, IActor
sender = sender ?? ActorRefs.NoSender;
return taskToPipe.ContinueWith(tresult =>
{
if (tresult.IsCanceled || tresult.IsFaulted)
if (tresult.IsFaulted)
recipient.Tell(failure != null
? failure(tresult.Exception)
: new Status.Failure(tresult.Exception), sender);
else if (tresult.IsCanceled)
{
var ex = tresult.Exception ?? new AggregateException(new TaskCanceledException());
recipient.Tell(failure != null
? failure(ex)
: new Status.Failure(ex), sender);
}
else if (tresult.IsCompleted)
recipient.Tell(success != null
? success(tresult.Result)
Expand All @@ -59,10 +66,17 @@ public static Task PipeTo(this Task taskToPipe, ICanTell recipient, IActorRef se
sender = sender ?? ActorRefs.NoSender;
return taskToPipe.ContinueWith(tresult =>
{
if (tresult.IsCanceled || tresult.IsFaulted)
if (tresult.IsFaulted)
recipient.Tell(failure != null
? failure(tresult.Exception)
: new Status.Failure(tresult.Exception), sender);
else if (tresult.IsCanceled)
{
var ex = tresult.Exception ?? new AggregateException(new TaskCanceledException());
recipient.Tell(failure != null
? failure(ex)
: new Status.Failure(ex), sender);
}
else if (tresult.IsCompleted && success != null)
recipient.Tell(success(), sender);
}, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
Expand Down

0 comments on commit 303d632

Please sign in to comment.