Mercurial > pub > ImplabNet
annotate Implab/PromiseAwaiterT.cs @ 207:558f34b2fb50 v2
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
added Safe.Dispose(IEnumerable)
added PromiseExtensions.CancellationPoint to add a cancellation point to the chain of promises
added IPromise<T> PromiseExtensions.Then<T>(this IPromise<T> that, Action<T> success) overloads
added PromiseExtensions.Error() overloads to handle a error or(and) a cancellation
| author | cin |
|---|---|
| date | Wed, 09 Nov 2016 12:03:22 +0300 |
| parents | ec91a6dfa5b3 |
| children | cbe10ac0731e |
| rev | line source |
|---|---|
| 151 | 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 |
