diff Implab/PromiseAwaiter.cs @ 151:ec91a6dfa5b3 v2

Added support for 'await' operator to promises
author cin
date Thu, 04 Feb 2016 02:43:05 +0300
parents
children cbe10ac0731e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab/PromiseAwaiter.cs	Thu Feb 04 02:43:05 2016 +0300
@@ -0,0 +1,28 @@
+using System;
+using System.Runtime.CompilerServices;
+
+namespace Implab {
+    public struct PromiseAwaiter : INotifyCompletion {
+        readonly IPromise m_promise;
+
+        public PromiseAwaiter(IPromise promise) {
+            m_promise = promise;
+        }
+
+        public void OnCompleted (Action continuation) {
+            if (m_promise != null)
+                m_promise.On(continuation, PromiseEventType.All);
+        }
+
+        public void GetResult() {
+            m_promise.Join();
+        }
+
+        public bool IsCompleted {
+            get {
+                return m_promise.IsResolved;
+            }
+        }
+    }
+}
+