示例#1
0
        private void AddPromiseHandles(IPromiser resultPromise, Action resolveHandle,
                                       Action <Exception> rejectHandle, Action <float> notifyHandle)
        {
            switch (CurrentState)
            {
            case PromiseState.Pending:
                if (resolveHandle != null)
                {
                    _resolveHandlers.Add(new ResolveInvoker(resultPromise, resolveHandle));
                }

                if (rejectHandle != null)
                {
                    _rejectHandlers.Add(new RejectInvoker(resultPromise, rejectHandle));
                }

                if (notifyHandle != null)
                {
                    _processHandlers.Add(new NotifyInvoker(resultPromise, notifyHandle));
                }

                break;

            case PromiseState.Rejected:
                try { rejectHandle.Invoke(_rejectedValue); }
                catch (Exception e) { resultPromise.Reject(e); }

                break;

            case PromiseState.Resolved:
                try { resolveHandle.Invoke(); }
                catch (Exception e) { resultPromise.Reject(e); }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#2
0
 public RejectInvoker(IPromiser rejector, Action <Exception> rejectHandler)
 {
     Rejector      = rejector;
     RejectHandler = rejectHandler;
 }
示例#3
0
 public ResolveInvoker(IPromiser rejector, Action resolvedHandler)
 {
     Rejector        = rejector;
     ResolvedHandler = resolvedHandler;
 }
示例#4
0
 public NotifyInvoker(IPromiser rejector, Action <float> notifyHandler)
 {
     Rejector      = rejector;
     NotifyHandler = notifyHandler;
 }