248
|
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 } |