diff Implab/Promise.cs @ 71:1714fd8678ef

code cleanup
author cin
date Wed, 03 Sep 2014 18:34:02 +0400
parents 790e8a997d30
children d67b95eddaf4
line wrap: on
line diff
--- a/Implab/Promise.cs	Wed Sep 03 11:57:43 2014 +0400
+++ b/Implab/Promise.cs	Wed Sep 03 18:34:02 2014 +0400
@@ -80,11 +80,11 @@
             }
         }
 
-        const int UnresolvedSate = 0;
-        const int TransitionalState = 1;
-        const int SucceededState = 2;
-        const int RejectedState = 3;
-        const int CancelledState = 4;
+        const int UNRESOLVED_SATE = 0;
+        const int TRANSITIONAL_STATE = 1;
+        const int SUCCEEDED_STATE = 2;
+        const int REJECTED_STATE = 3;
+        const int CANCELLED_STATE = 4;
 
         readonly bool m_cancellable;
 
@@ -113,16 +113,16 @@
         }
 
         bool BeginTransit() {
-            return UnresolvedSate == Interlocked.CompareExchange(ref m_state, TransitionalState, UnresolvedSate);
+            return UNRESOLVED_SATE == Interlocked.CompareExchange(ref m_state, TRANSITIONAL_STATE, UNRESOLVED_SATE);
         }
 
         void CompleteTransit(int state) {
-            if (TransitionalState != Interlocked.CompareExchange(ref m_state, state, TransitionalState))
+            if (TRANSITIONAL_STATE != Interlocked.CompareExchange(ref m_state, state, TRANSITIONAL_STATE))
                 throw new InvalidOperationException("Can't complete transition when the object isn't in the transitional state");
         }
 
         void WaitTransition() {
-            while (m_state == TransitionalState) {
+            while (m_state == TRANSITIONAL_STATE) {
                 /* noop */
             }
         }
@@ -135,7 +135,7 @@
 
         public bool IsCancelled {
             get {
-                return m_state == CancelledState;
+                return m_state == CANCELLED_STATE;
             }
         }
 
@@ -151,11 +151,11 @@
         public void Resolve(T result) {
             if (BeginTransit()) {
                 m_result = result;
-                CompleteTransit(SucceededState);
+                CompleteTransit(SUCCEEDED_STATE);
                 OnStateChanged();
             } else {
                 WaitTransition();
-                if (m_state != CancelledState)
+                if (m_state != CANCELLED_STATE)
                     throw new InvalidOperationException("The promise is already resolved");
             }
         }
@@ -183,11 +183,11 @@
         public void Reject(Exception error) {
             if (BeginTransit()) {
                 m_error = error;
-                CompleteTransit(RejectedState);
+                CompleteTransit(REJECTED_STATE);
                 OnStateChanged();
             } else {
                 WaitTransition();
-                if (m_state == SucceededState)
+                if (m_state == SUCCEEDED_STATE)
                     throw new InvalidOperationException("The promise is already resolved");
             }
         }
@@ -198,7 +198,7 @@
         /// <returns><c>true</c> Операция была отменена, обработчики не будут вызваны.<c>false</c> отмена не возможна, поскольку обещание уже выполнено и обработчики отработали.</returns>
         public bool Cancel() {
             if (BeginTransit()) {
-                CompleteTransit(CancelledState);
+                CompleteTransit(CANCELLED_STATE);
                 OnStateChanged();
                 return true;
             } else {
@@ -545,11 +545,11 @@
                 throw new TimeoutException();
 
             switch (m_state) {
-                case SucceededState:
+                case SUCCEEDED_STATE:
                     return m_result;
-                case CancelledState:
+                case CANCELLED_STATE:
                     throw new OperationCanceledException();
-                case RejectedState:
+                case REJECTED_STATE:
                     throw new TargetInvocationException(m_error);
                 default:
                     throw new ApplicationException(String.Format("Invalid promise state {0}", m_state));
@@ -592,13 +592,13 @@
 
         protected virtual void InvokeHandler(HandlerDescriptor handler) {
             switch (m_state) {
-                case SucceededState:
+                case SUCCEEDED_STATE:
                     handler.Resolve(m_result);
                     break;
-                case RejectedState:
+                case REJECTED_STATE:
                     handler.Reject(m_error);
                     break;
-                case CancelledState:
+                case CANCELLED_STATE:
                     handler.Cancel();
                     break;
                 default: