diff Implab/SyncContextPromise.cs @ 72:d67b95eddaf4 v2

promises refactoring
author cin
date Thu, 04 Sep 2014 18:47:12 +0400
parents
children 279e226dffdd
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab/SyncContextPromise.cs	Thu Sep 04 18:47:12 2014 +0400
@@ -0,0 +1,22 @@
+using System.Threading;
+
+namespace Implab {
+    public class SyncContextPromise<T> : Promise<T> {
+        readonly SynchronizationContext m_context;
+
+        public SyncContextPromise(SynchronizationContext context) {
+            Safe.ArgumentNotNull(context, "context");
+            m_context = context;
+        }
+
+        public SyncContextPromise(SynchronizationContext context, IPromise parent, bool cancellable)
+            : base(parent, cancellable) {
+            Safe.ArgumentNotNull(context, "context");
+            m_context = context;
+        }
+        protected override void InvokeHandler(HandlerDescriptor handler) {
+            m_context.Post(x => base.InvokeHandler(handler),null);
+        }
+    }
+}
+