Mercurial > pub > ImplabNet
annotate Implab/SuccessPromiseT.cs @ 239:eedf4d834e67 v2
fix
author | cin |
---|---|
date | Wed, 13 Dec 2017 19:54:45 +0300 |
parents | 4d9830a9bbb8 |
children | cbe10ac0731e |
rev | line source |
---|---|
145 | 1 using System; |
2 | |
3 namespace Implab { | |
4 public class SuccessPromise<T> : IPromise<T> { | |
5 readonly T m_value; | |
6 | |
7 public SuccessPromise(T value){ | |
8 m_value = value; | |
9 } | |
10 | |
11 public IPromise<T> On(Action<T> success, Action<Exception> error, Action<Exception> cancel) { | |
12 if (success != null) { | |
13 try { | |
14 success(m_value); | |
203
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
145
diff
changeset
|
15 // Analysis disable once EmptyGeneralCatchClause |
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
145
diff
changeset
|
16 } catch { |
145 | 17 } |
18 } | |
19 return this; | |
20 } | |
21 | |
22 public IPromise<T> On(Action<T> success, Action<Exception> error) { | |
23 if (success != null) { | |
24 try { | |
25 success(m_value); | |
203
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
145
diff
changeset
|
26 // Analysis disable once EmptyGeneralCatchClause |
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
145
diff
changeset
|
27 } catch { |
145 | 28 } |
29 } | |
30 return this; | |
31 } | |
32 | |
33 public IPromise<T> On(Action<T> success) { | |
34 if (success != null) { | |
35 try { | |
36 success(m_value); | |
37 // Analysis disable once EmptyGeneralCatchClause | |
38 } catch { | |
39 } | |
40 } | |
41 return this; | |
42 } | |
43 | |
44 public T Join() { | |
45 return m_value; | |
46 } | |
47 | |
48 public T Join(int timeout) { | |
49 return m_value; | |
50 } | |
51 | |
52 public IPromise<T> On(Action success, Action<Exception> error, Action<Exception> cancel) { | |
53 if (success != null) { | |
54 try { | |
55 success(); | |
203
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
145
diff
changeset
|
56 // Analysis disable once EmptyGeneralCatchClause |
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
145
diff
changeset
|
57 } catch { |
145 | 58 } |
59 } | |
60 return this; | |
61 } | |
62 | |
63 public IPromise<T> On(Action success, Action<Exception> error) { | |
64 if (success != null) { | |
65 try { | |
66 success(); | |
203
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
145
diff
changeset
|
67 // Analysis disable once EmptyGeneralCatchClause |
4d9830a9bbb8
Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
145
diff
changeset
|
68 } catch { |
145 | 69 } |
70 } | |
71 return this; | |
72 } | |
73 | |
74 public IPromise<T> On(Action success) { | |
75 if (success != null) { | |
76 try { | |
77 success(); | |
78 // Analysis disable once EmptyGeneralCatchClause | |
79 } catch { | |
80 } | |
81 } | |
82 return this; | |
83 } | |
84 | |
85 public IPromise<T> On(Action handler, PromiseEventType events) { | |
86 if (handler != null && events.HasFlag(PromiseEventType.Success)) { | |
87 try { | |
88 handler(); | |
89 // Analysis disable once EmptyGeneralCatchClause | |
90 } catch { | |
91 } | |
92 } | |
93 return this; | |
94 } | |
95 | |
96 IPromise IPromise.On(Action success, Action<Exception> error, Action<Exception> cancel) { | |
97 return On(success, error, cancel); | |
98 } | |
99 | |
100 IPromise IPromise.On(Action success, Action<Exception> error) { | |
101 return On(success, error); | |
102 } | |
103 | |
104 IPromise IPromise.On(Action success) { | |
105 return On(success); | |
106 } | |
107 | |
108 IPromise IPromise.On(Action handler, PromiseEventType events) { | |
109 return On(handler, events); | |
110 } | |
111 | |
112 public IPromise<T2> Cast<T2>() { | |
113 return new SuccessPromise<T2>((T2)(object)m_value); | |
114 } | |
115 | |
116 void IPromise.Join() { | |
117 } | |
118 | |
119 void IPromise.Join(int timeout) { | |
120 } | |
121 | |
122 public Type PromiseType { | |
123 get { | |
124 return typeof(T); | |
125 } | |
126 } | |
127 | |
128 public bool IsResolved { | |
129 get { | |
130 return true; | |
131 } | |
132 } | |
133 | |
134 public bool IsCancelled { | |
135 get { | |
136 return false; | |
137 } | |
138 } | |
139 | |
140 public Exception Error { | |
141 get { | |
142 return null; | |
143 } | |
144 } | |
145 | |
146 public void Cancel() { | |
147 } | |
148 | |
149 public void Cancel(Exception reason) { | |
150 } | |
151 } | |
152 } | |
153 |