예제 #1
0
        /// <summary>
        /// The Wrapping does 2 things:
        /// (1) propagate error to other children of the host
        /// (2) call completion back of the child
        /// </summary>
        protected Task GetWrappedCompletion(Task rawCompletion)
        {
            var tcs = new TaskCompletionSource <object>();

            rawCompletion.ContinueWith(task =>
            {
                if (task.Status == TaskStatus.Faulted)
                {
                    var exception = TaskEx.UnwrapWithPriority(task.Exception);
                    tcs.SetException(exception);

                    if (!(exception is PropagatedException))
                    {
                        m_host.Fault(exception); //fault other blocks if this is an original exception
                    }
                }
                else if (task.Status == TaskStatus.Canceled)
                {
                    tcs.SetCanceled();
                    m_host.Fault(new TaskCanceledException());
                }
                else //success
                {
                    try
                    {
                        //call callback
                        if (m_completionCallback != null)
                        {
                            m_completionCallback(task);
                        }
                        tcs.SetResult(string.Empty);
                    }
                    catch (Exception e)
                    {
                        LogHelper.Logger.Error(h => h("[{0}] Error when callback {1} on its completion", m_host.Name, this.DisplayName), e);
                        tcs.SetException(e);
                        m_host.Fault(e);
                    }
                }
            });

            return(tcs.Task);
        }
예제 #2
0
 public override void Fault(Exception e)
 {
     m_childContainer.Fault(e);
 }