annotate Implab/PromiseAwaiter.cs @ 187:dd4a3590f9c6 ref20160224

Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler Any unhandled OperationCanceledException will cause the promise cancelation
author cin
date Tue, 19 Apr 2016 17:35:20 +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