/// <summary>
        /// Handle errors for the promise.
        /// </summary>
        public IPromise Catch(Action <Exception> onRejected)
        {
//            Argument.NotNull(() => onRejected);

            if (CurState == PromiseState.Resolved)
            {
                return(this);
            }
            else if (CurState == PromiseState.Rejected)
            {
                try
                {
                    onRejected(rejectionException);

                    return(Promise.Resolved());
                }
                catch (Exception ex)
                {
                    return(Promise.RejectedStatic(ex));
                }
            }
            else
            {
                return(CatchPending(onRejected));
            }
        }
示例#2
0
        /// <summary>
        /// Add a resolved callback and a rejected callback.
        /// </summary>
        public IPromise Then(Action <PromisedT> onResolved, Action <Exception> onRejected)
        {
            if (CurState == PromiseState.Resolved)
            {
                try
                {
                    onResolved(resolveValue);
                    return(Promise.Resolved());
                }
                catch (Exception ex)
                {
                    return(Promise.Rejected(ex));
                }
            }
            else if (CurState == PromiseState.Rejected)
            {
                try
                {
                    if (onRejected != null)
                    {
                        onRejected(rejectionException);

                        return(Promise.RejectedStatic(rejectionException));
                    }
                    else
                    {
                        return(Promise.RejectedStatic(rejectionException));
                    }
                }
                catch (Exception ex)
                {
                    return(Promise.RejectedStatic(ex));
                }
            }
            else
            {
                return(ThenPending(onResolved, onRejected));
            }
        }
示例#3
0
        /// <summary>
        /// Handle errors for the promise.
        /// </summary>
        public IPromise <PromisedT> Catch(Func <Exception, PromisedT> onRejected)
        {
            if (CurState == PromiseState.Resolved)
            {
                return(this);
            }
            else if (CurState == PromiseState.Rejected)
            {
                try
                {
                    PromisedT retVal = onRejected(rejectionException);

                    return(Promise <PromisedT> .Resolved(retVal));
                }
                catch (Exception ex)
                {
                    return(Promise <PromisedT> .RejectedStatic(ex));
                }
            }
            else
            {
                return(CatchPending(onRejected));
            }
        }
示例#4
0
        /// <summary>
        /// Handle errors for the promise.
        /// </summary>
        public IPromise Catch(Action <Exception> onRejected)
        {
            if (CurState == PromiseState.Resolved)
            {
                return(Promise.Resolved());
            }
            else if (CurState == PromiseState.Rejected)
            {
                try
                {
                    onRejected(rejectionException);

                    return(Promise.Resolved());
                }
                catch (Exception ex)
                {
                    return(Promise.RejectedStatic(ex));
                }
            }
            else
            {
                return(CatchPending(onRejected));
            }
        }