Mercurial > pub > ImplabNet
comparison Implab/PromiseAwaiterT.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 |
comparison
equal
deleted
inserted
replaced
150:3258399cba83 | 151:ec91a6dfa5b3 |
---|---|
1 using System; | |
2 using System.Runtime.CompilerServices; | |
3 | |
4 namespace Implab { | |
5 public struct PromiseAwaiter<T> : INotifyCompletion { | |
6 readonly IPromise<T> m_promise; | |
7 | |
8 public PromiseAwaiter(IPromise<T> promise) { | |
9 m_promise = promise; | |
10 } | |
11 | |
12 public void OnCompleted (Action continuation) { | |
13 if (m_promise != null) | |
14 m_promise.On(continuation, PromiseEventType.All); | |
15 } | |
16 | |
17 public T GetResult() { | |
18 return m_promise.Join(); | |
19 } | |
20 | |
21 public bool IsCompleted { | |
22 get { | |
23 return m_promise.IsResolved; | |
24 } | |
25 } | |
26 } | |
27 } | |
28 |