Skip to content

Commit

Permalink
Merge pull request #978 from adamhathcock/pipeto_exception
Browse files Browse the repository at this point in the history
Add PipeTo for non-generic Tasks for exception handling
  • Loading branch information
rogeralsing committed May 15, 2015
2 parents e3aab4c + 7c5a7a3 commit cbe4975
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/core/Akka/Actor/PipeToSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,26 @@ 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.IsCanceled || tresult.IsFaulted)
recipient.Tell(new Status.Failure(tresult.Exception), sender);
else if (tresult.IsCompleted)
recipient.Tell(tresult.Result, sender);
}, TaskContinuationOptions.ExecuteSynchronously & TaskContinuationOptions.AttachedToParent);
}

/// <summary>
/// Pipes the output of a Task directly to the <see cref="recipient"/>'s mailbox once
/// the task completes. As this task has no result, only exceptions will be piped to the <see cref="recipient"/>
/// </summary>
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);
}
}
}

0 comments on commit cbe4975

Please sign in to comment.