diff Implab/PromiseReaction`1.cs @ 248:5cb4826c2c2a v3

Added awaiters to promises Added static methods to Promise Resolve, Reject, All. Updated promise helpers
author cin
date Tue, 30 Jan 2018 01:37:17 +0300
parents fb70574741a1
children
line wrap: on
line diff
--- a/Implab/PromiseReaction`1.cs	Fri Jan 26 18:46:27 2018 +0300
+++ b/Implab/PromiseReaction`1.cs	Tue Jan 30 01:37:17 2018 +0300
@@ -1,6 +1,11 @@
 using System;
 
 namespace Implab {
+    /// <summary>
+    /// Базовыйй класс для создания обработчиков результов выполнения обещаний.
+    /// Данный объект связывает обработчик и обешание, при этом для выполнения
+    /// обработчика будет использоваться диспетчер.
+    /// </summary>
     abstract class PromiseReaction<T> : IResolvable<T> {
         readonly IDispatcher m_dispatcher;
 
@@ -8,36 +13,28 @@
             m_dispatcher = dispatcher;
         }
 
-        protected abstract bool HasFulfilHandler {
-            get;
-        }
+        protected Action<T> FulfilHandler { get; set; }
 
-        protected abstract bool HasRejectHandler {
-            get;
-        }
+        protected Action<Exception> RejectHandler { get; set; }
 
         public void Reject(Exception error) {
-            if (!HasRejectHandler)
+            if (RejectHandler == null)
                 DefaultReject(error);
             else if (m_dispatcher != null)
-                m_dispatcher.Enqueue(() => RejectImpl(error));
+                m_dispatcher.Enqueue(RejectHandler, error);
             else
-                RejectImpl(error);
+                RejectHandler(error);
         }
 
         public void Resolve(T result) {
-            if (!HasFulfilHandler)
+            if (FulfilHandler == null)
                 DefaultResolve(result);
             else if (m_dispatcher != null)
-                m_dispatcher.Enqueue(() => ResolveImpl(result));
+                m_dispatcher.Enqueue(FulfilHandler, result);
             else
-                ResolveImpl(result);
+                FulfilHandler(result);
         }
 
-        protected abstract void ResolveImpl(T result);
-
-        protected abstract void RejectImpl(Exception reason);
-
         protected abstract void DefaultResolve(T result);
 
         protected abstract void DefaultReject(Exception reason);