248
|
1 using System;
|
|
2
|
|
3 namespace Implab
|
|
4 {
|
|
5 public struct RejectedPromise<T> : IPromise<T> {
|
|
6 readonly Exception m_reason;
|
|
7
|
|
8 public Type ResultType => typeof(void);
|
|
9
|
|
10 public bool IsResolved => true;
|
|
11
|
|
12 public bool IsRejected => true;
|
|
13
|
|
14 public bool IsFulfilled => false;
|
|
15
|
|
16 public Exception RejectReason => m_reason;
|
|
17
|
|
18 public RejectedPromise(Exception reason) {
|
|
19 m_reason = reason;
|
|
20 }
|
|
21
|
|
22 public IPromise<T2> Cast<T2>() {
|
|
23 return (IPromise<T2>)(IPromise<T>)this;
|
|
24 }
|
|
25
|
|
26 void IPromise.Join() {
|
|
27 m_reason.ThrowInvocationException();
|
|
28 }
|
|
29
|
|
30 void IPromise.Join(int timeout) {
|
|
31 m_reason.ThrowInvocationException();
|
|
32 }
|
|
33
|
|
34 public T Join() {
|
|
35 m_reason.ThrowInvocationException();
|
|
36 throw new Exception(); // unreachable code
|
|
37 }
|
|
38
|
|
39 public T Join(int timeout) {
|
|
40 m_reason.ThrowInvocationException();
|
|
41 throw new Exception(); // unreachable code
|
|
42 }
|
|
43
|
|
44 public void Then(IResolvable next) {
|
|
45 next.Reject(m_reason);
|
|
46 }
|
|
47
|
|
48 public void Then(IResolvable<T> next) {
|
|
49 next.Reject(m_reason);
|
|
50 }
|
|
51 }
|
|
52 } |