diff Implab/AbstractPromiseT.cs @ 145:706fccb85524 v2

RC: cancellation support for promises + tests
author cin
date Sun, 08 Mar 2015 02:52:27 +0300
parents 8c0b95069066
children 97fbbf816844
line wrap: on
line diff
--- a/Implab/AbstractPromiseT.cs	Fri Mar 06 15:45:26 2015 +0300
+++ b/Implab/AbstractPromiseT.cs	Sun Mar 08 02:52:27 2015 +0300
@@ -14,10 +14,14 @@
                 m_success = success;
                 m_error = error;
                 m_cancel = cancel;
+
+                m_handler = null;
+                m_mask = 0;
             }
 
             public HandlerDescriptor(Action success, Action<Exception> error, Action<Exception> cancel) {
                 m_handler = success;
+                m_success = null;
                 m_error = error;
                 m_cancel = cancel;
                 m_mask = PromiseEventType.Success;
@@ -26,6 +30,9 @@
             public HandlerDescriptor(Action handler, PromiseEventType mask) {
                 m_handler = handler;
                 m_mask = mask;
+                m_success = null;
+                m_error = null;
+                m_cancel = null;
             }
 
             public void SignalSuccess(T result) {
@@ -35,7 +42,7 @@
                     } catch(Exception err) {
                         SignalError(err);
                     }
-                } else if (m_mask & PromiseEventType.Success && m_handler != null) {
+                } else if ((m_mask & PromiseEventType.Success) != 0 && m_handler != null) {
                     try {
                         m_handler();
                     } catch(Exception err) {
@@ -53,7 +60,7 @@
                         // Analysis disable once EmptyGeneralCatchClause
                     } catch {
                     }
-                } else if (m_mask & PromiseEventType.Error && m_handler != null) {
+                } else if ((m_mask & PromiseEventType.Error) != 0 && m_handler != null) {
                     try {
                         m_handler();
                         // Analysis disable once EmptyGeneralCatchClause
@@ -69,7 +76,7 @@
                     } catch (Exception err) {
                         SignalError(err);
                     }
-                } else if (m_mask & PromiseEventType.Cancelled && m_handler != null) {
+                } else if ((m_mask & PromiseEventType.Cancelled) != 0 && m_handler != null) {
                     try {
                         m_handler();
                         // Analysis disable once EmptyGeneralCatchClause
@@ -79,23 +86,28 @@
             }
         }
 
-
-
         public Type PromiseType {
             get {
                 return typeof(T);
             }
         }
 
-        public new T Join() {
+        public T Join() {
             WaitResult(-1);
             return m_result;
         }
-        public new T Join(int timeout) {
+        public T Join(int timeout) {
             WaitResult(timeout);
             return m_result;
         }
 
+        void IPromise.Join() {
+            WaitResult(-1);
+        }
+        void IPromise.Join(int timeout) {
+            WaitResult(timeout);
+        }
+
         public IPromise<T> On(Action<T> success, Action<Exception> error, Action<Exception> cancel) {
             AddHandler(new HandlerDescriptor(success, error, cancel));
             return this;
@@ -146,6 +158,11 @@
             return this;
         }
 
+        IPromise IPromise.On(Action handler, PromiseEventType events) {
+            AddHandler(new HandlerDescriptor(handler, events));
+            return this;
+        }
+
         public IPromise<T2> Cast<T2>() {
             return (IPromise<T2>)this;
         }