comparison Implab/PromiseAll.cs @ 248:5cb4826c2c2a v3

Added awaiters to promises Added static methods to Promise Resolve, Reject, All. Updated promise helpers
author cin
date Tue, 30 Jan 2018 01:37:17 +0300
parents
children
comparison
equal deleted inserted replaced
247:fb70574741a1 248:5cb4826c2c2a
1 using System;
2 using System.Threading;
3
4 namespace Implab
5 {
6 class PromiseAll : IResolvable {
7 int m_count;
8
9 readonly Deferred m_deferred;
10
11 public bool Done {
12 get { return m_deferred.Promise.IsResolved; }
13 }
14
15 public IPromise ResultPromise {
16 get { return m_deferred.Promise; }
17 }
18
19 public void AddPromise(IPromise promise) {
20 Interlocked.Increment(ref m_count);
21 }
22
23 public PromiseAll(Deferred deferred) {
24 m_deferred = deferred;
25 }
26
27 public void Resolve() {
28 if (Interlocked.Decrement(ref m_count) == 0)
29 m_deferred.Resolve();
30 }
31
32 public void Complete() {
33 Resolve();
34 }
35
36 public void Reject(Exception error) {
37 m_deferred.Reject(error);
38 }
39 }
40 }