comparison Implab/RejectedPromise`1.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 d82909310094
comparison
equal deleted inserted replaced
247:fb70574741a1 248:5cb4826c2c2a
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 }