Exemplo n.º 1
0
        public Fpromise(Action <Action <FpromisedT>, Action <Exception> > resolver)
        {
            this.CurState = FpromiseState.Pending;
            this.Id       = ++Fpromise.nextFpromiseId;

            if (Fpromise.EnableFpromiseTracking)
            {
                Fpromise.pendingFpromises.Add(this);
            }

            try
            {
                resolver(
                    // Resolve
                    value => Resolve(value),

                    // Reject
                    ex => Reject(ex)
                    );
            }
            catch (Exception ex)
            {
                Reject(ex);
            }
        }
Exemplo n.º 2
0
 public Fpromise()
 {
     this.CurState = FpromiseState.Pending;
     if (EnableFpromiseTracking)
     {
         pendingFpromises.Add(this);
     }
 }
Exemplo n.º 3
0
        public Fpromise()
        {
            this.CurState = FpromiseState.Pending;
            this.Id       = ++Fpromise.nextFpromiseId;

            if (Fpromise.EnableFpromiseTracking)
            {
                Fpromise.pendingFpromises.Add(this);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Resolve the promise with a particular value.
        /// </summary>
        public void Resolve()
        {
            if (CurState != FpromiseState.Pending)
            {
                throw new ApplicationException("Attempt to resolve a promise that is already in state: " + CurState + ", a promise can only be resolved when it is still in state: " + FpromiseState.Pending);
            }

            CurState = FpromiseState.Resolved;

            if (EnableFpromiseTracking)
            {
                pendingFpromises.Remove(this);
            }

            InvokeResolveHandlers();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reject the promise with an exception.
        /// </summary>
        public void Reject(Exception ex)
        {
            //            Argument.NotNull(() => ex);

            if (CurState != FpromiseState.Pending)
            {
                throw new ApplicationException("Attempt to reject a promise that is already in state: " + CurState + ", a promise can only be rejected when it is still in state: " + FpromiseState.Pending);
            }

            rejectionException = ex;
            CurState           = FpromiseState.Rejected;

            if (EnableFpromiseTracking)
            {
                pendingFpromises.Remove(this);
            }

            InvokeRejectHandlers(ex);
        }
Exemplo n.º 6
0
        public Fpromise(Action <Action, Action <Exception> > resolver)
        {
            this.CurState = FpromiseState.Pending;
            if (EnableFpromiseTracking)
            {
                pendingFpromises.Add(this);
            }

            try
            {
                resolver(
                    // Resolve
                    () => Resolve(),

                    // Reject
                    ex => Reject(ex)
                    );
            }
            catch (Exception ex)
            {
                Reject(ex);
            }
        }