annotate Implab/PromiseAwaiterT.cs @ 243:b1e0ffdf3451 v3

working on promises
author cin
date Wed, 24 Jan 2018 19:24:10 +0300
parents cbe10ac0731e
children
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 {
242
cbe10ac0731e Working on promises
cin
parents: 151
diff changeset
23 return m_promise.IsFulfilled;
151
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