annotate Implab/PromiseAwaiter.cs @ 213:9ee78a345738 v2

Minor code changes
author cin
date Tue, 11 Apr 2017 01:35:18 +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 : INotifyCompletion {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
6 readonly IPromise 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 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 void GetResult() {
ec91a6dfa5b3 Added support for 'await' operator to promises
cin
parents:
diff changeset
18 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