From 7c5a7a344e41da4afd7a53e301d09a24650557f1 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 14 May 2015 14:12:49 +0100 Subject: [PATCH] Add PipeTo for non-generic Tasks for exception handling --- src/core/Akka/Actor/PipeToSupport.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/Akka/Actor/PipeToSupport.cs b/src/core/Akka/Actor/PipeToSupport.cs index 3fd3a1ddbc3..aee24df3625 100644 --- a/src/core/Akka/Actor/PipeToSupport.cs +++ b/src/core/Akka/Actor/PipeToSupport.cs @@ -24,12 +24,26 @@ public static Task PipeTo(this Task taskToPipe, ICanTell recipient, IActor sender = sender ?? ActorRefs.NoSender; return taskToPipe.ContinueWith(tresult => { - if(tresult.IsCanceled || tresult.IsFaulted) + if (tresult.IsCanceled || tresult.IsFaulted) recipient.Tell(new Status.Failure(tresult.Exception), sender); else if (tresult.IsCompleted) recipient.Tell(tresult.Result, sender); }, TaskContinuationOptions.ExecuteSynchronously & TaskContinuationOptions.AttachedToParent); } + + /// + /// Pipes the output of a Task directly to the 's mailbox once + /// the task completes. As this task has no result, only exceptions will be piped to the + /// + public static Task PipeTo(this Task taskToPipe, ICanTell recipient, IActorRef sender = null) + { + sender = sender ?? ActorRefs.NoSender; + return taskToPipe.ContinueWith(tresult => + { + if (tresult.IsCanceled || tresult.IsFaulted) + recipient.Tell(new Status.Failure(tresult.Exception), sender); + }, TaskContinuationOptions.ExecuteSynchronously & TaskContinuationOptions.AttachedToParent); + } } }