@@ -51,7 +51,7 namespace Implab.Fx | |||||
51 | { |
|
51 | { | |
52 | var timer = new Timer(m_delay); |
|
52 | var timer = new Timer(m_delay); | |
53 |
|
53 | |||
54 |
timer.AutoReset = |
|
54 | timer.AutoReset = false; | |
55 | timer.SynchronizingObject = m_syncronizationObject; |
|
55 | timer.SynchronizingObject = m_syncronizationObject; | |
56 | timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); |
|
56 | timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); | |
57 |
|
57 |
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -151,27 +151,69 namespace Implab { | |||||
151 |
|
|
151 | if (success == null && error == null) | |
152 | return this; |
|
152 | return this; | |
153 |
|
153 | |||
154 | AddHandler(new ResultHandlerInfo() { |
|
154 | var medium = new Promise<T>(); | |
155 | resultHandler = success, |
|
155 | ||
156 | errorHandler = error |
|
156 | var handlerInfo = new ResultHandlerInfo(); | |
157 | }); |
|
|||
158 |
|
157 | |||
159 | return this; |
|
158 | if (success != null) | |
|
159 | handlerInfo.resultHandler = x => { | |||
|
160 | try { | |||
|
161 | success(x); | |||
|
162 | medium.Resolve(x); | |||
|
163 | } catch (Exception e) { | |||
|
164 | medium.Reject(e); | |||
|
165 | } | |||
|
166 | }; | |||
|
167 | else | |||
|
168 | handlerInfo.resultHandler = x => medium.Resolve(x); | |||
|
169 | ||||
|
170 | if (error != null) | |||
|
171 | handlerInfo.errorHandler = x => { | |||
|
172 | try { | |||
|
173 | error(x); | |||
|
174 | } catch { } | |||
|
175 | medium.Reject(x); | |||
|
176 | }; | |||
|
177 | else | |||
|
178 | handlerInfo.errorHandler = x => medium.Reject(x); | |||
|
179 | ||||
|
180 | AddHandler(handlerInfo); | |||
|
181 | ||||
|
182 | return medium; | |||
160 | } |
|
183 | } | |
161 |
|
184 | |||
162 |
|
|
185 | public Promise<T> Then(ResultHandler<T> success) { | |
163 |
|
|
186 | return Then(success, null); | |
164 | } |
|
187 | } | |
165 |
|
188 | |||
|
189 | public Promise<T> Error(ErrorHandler error) { | |||
|
190 | return Then(null, error); | |||
|
191 | } | |||
|
192 | ||||
166 |
|
|
193 | public Promise<T> Anyway(Action handler) { | |
167 |
|
|
194 | if (handler == null) | |
168 | return this; |
|
195 | return this; | |
|
196 | ||||
|
197 | var medium = new Promise<T>(); | |||
|
198 | ||||
169 |
|
|
199 | AddHandler(new ResultHandlerInfo { | |
170 | resultHandler = x => handler(), |
|
200 | resultHandler = x => { | |
171 | errorHandler = x => handler() |
|
201 | try { | |
|
202 | handler(); | |||
|
203 | medium.Resolve(x); | |||
|
204 | } catch (Exception e) { | |||
|
205 | medium.Reject(e); | |||
|
206 | } | |||
|
207 | }, | |||
|
208 | errorHandler = x => { | |||
|
209 | try { | |||
|
210 | handler(); | |||
|
211 | } catch { } | |||
|
212 | medium.Reject(x); | |||
|
213 | } | |||
172 | }); |
|
214 | }); | |
173 |
|
215 | |||
174 | return this; |
|
216 | return medium; | |
175 | } |
|
217 | } | |
176 |
|
218 | |||
177 |
|
|
219 | /// <summary> |
General Comments 0
You need to be logged in to leave comments.
Login now