diff Implab/AbstractEvent.cs @ 244:eee3e49dd1ff v3

working on promises
author cin
date Thu, 25 Jan 2018 19:09:16 +0300
parents b1e0ffdf3451
children 5cb4826c2c2a
line wrap: on
line diff
--- a/Implab/AbstractEvent.cs	Wed Jan 24 19:24:10 2018 +0300
+++ b/Implab/AbstractEvent.cs	Thu Jan 25 19:09:16 2018 +0300
@@ -35,31 +35,31 @@
     /// </para>
     /// </remarks>
     public abstract class AbstractEvent<THandler> where THandler : class {
-        const int PENDING_SATE = 0;
+        const int PendingState = 0;
 
-        const int TRANSITIONAL_STATE = 1;
+        const int TransitionalState = 1;
 
-        const int FULFILLED_STATE = 2;
+        const int ResolvedState = 2;
 
         volatile int m_state;
 
         THandler m_handler;
         SimpleAsyncQueue<THandler> m_extraHandlers;
 
-        public bool IsFulfilled {
+        public bool IsResolved {
             get {
-                return m_state > TRANSITIONAL_STATE;
+                return m_state > TransitionalState;
             }
         }
 
         #region state managment
         protected bool BeginTransit() {
-            return PENDING_SATE == Interlocked.CompareExchange(ref m_state, TRANSITIONAL_STATE, PENDING_SATE);
+            return PendingState == Interlocked.CompareExchange(ref m_state, TransitionalState, PendingState);
         }
 
         protected void CompleteTransit() {
 #if DEBUG
-            if (TRANSITIONAL_STATE != Interlocked.CompareExchange(ref m_state, FULFILLED_STATE, TRANSITIONAL_STATE))
+            if (TransitionalState != Interlocked.CompareExchange(ref m_state, ResolvedState, TransitionalState))
                 throw new InvalidOperationException("Can't complete transition when the object isn't in the transitional state");
 #else
             m_state = state;
@@ -68,11 +68,11 @@
         }
 
         protected void WaitTransition() {
-            if (m_state == TRANSITIONAL_STATE) {
+            if (m_state == TransitionalState) {
                 SpinWait spin;
                 do {
                     spin.SpinOnce();
-                } while (m_state == TRANSITIONAL_STATE);
+                } while (m_state == TransitionalState);
             }
         }
 
@@ -91,7 +91,7 @@
 
         #region synchronization traits
         protected void WaitResult(int timeout) {
-            if (!(IsFulfilled || GetFulfillSignal().Wait(timeout)))
+            if (!(IsResolved || GetFulfillSignal().Wait(timeout)))
                 throw new TimeoutException();
         }
 
@@ -102,13 +102,13 @@
 
         protected void AddHandler(THandler handler) {
 
-            if (IsFulfilled) {
+            if (IsResolved) {
                 // the promise is in the resolved state, just invoke the handler
                 SignalHandler(handler);
             } else {
                 EnqueueHandler(handler);
 
-                if (IsFulfilled && TryDequeueHandler(out handler))
+                if (IsResolved && TryDequeueHandler(out handler))
                     // if the promise have been resolved while we was adding the handler to the queue
                     // we can't guarantee that someone is still processing it
                     // therefore we need to fetch a handler from the queue and execute it