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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
151
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
1 using System;
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
2 using System.Runtime.CompilerServices;
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
3
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
4 namespace Implab {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
5 public struct PromiseAwaiter<T> : INotifyCompletion {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
6 readonly IPromise<T> m_promise;
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
7
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
8 public PromiseAwaiter(IPromise<T> promise) {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
9 m_promise = promise;
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
10 }
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
11
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
12 public void OnCompleted (Action continuation) {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
13 if (m_promise != null)
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
14 m_promise.On(continuation, PromiseEventType.All);
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
15 }
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
16
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
17 public T GetResult() {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
18 return m_promise.Join();
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
19 }
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
20
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
21 public bool IsCompleted {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
22 get {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
23 return m_promise.IsResolved;
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
24 }
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
25 }
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
26 }
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
27 }
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
28