diff Implab/PromiseAwaiterT.cs @ 192:f1da3afc3521 release v2.1

Слияние с v2
author cin
date Fri, 22 Apr 2016 13:10:34 +0300
parents ec91a6dfa5b3
children cbe10ac0731e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab/PromiseAwaiterT.cs	Fri Apr 22 13:10:34 2016 +0300
@@ -0,0 +1,28 @@
+using System;
+using System.Runtime.CompilerServices;
+
+namespace Implab {
+    public struct PromiseAwaiter<T> : INotifyCompletion {
+        readonly IPromise<T> m_promise;
+
+        public PromiseAwaiter(IPromise<T> promise) {
+            m_promise = promise;
+        }
+
+        public void OnCompleted (Action continuation) {
+            if (m_promise != null)
+                m_promise.On(continuation, PromiseEventType.All);
+        }
+
+        public T GetResult() {
+            return m_promise.Join();
+        }
+
+        public bool IsCompleted {
+            get {
+                return m_promise.IsResolved;
+            }
+        }
+    }
+}
+