annotate Implab/PromiseAwaiterT.cs @ 209:a867536c68fc v2

Bound promise to CancellationToken Added new states to ExecutionSate enum. Added Safe.Guard() method to handle cleanup of the result of the promise
author cin
date Wed, 16 Nov 2016 03:06:08 +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