Mercurial > pub > ImplabNet
comparison Implab/Components/RunnableComponent.cs @ 187:dd4a3590f9c6 ref20160224
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler
Any unhandled OperationCanceledException will cause the promise cancelation
author | cin |
---|---|
date | Tue, 19 Apr 2016 17:35:20 +0300 |
parents | 75103928da09 |
children | 40d7fed4a09e |
comparison
equal
deleted
inserted
replaced
186:75103928da09 | 187:dd4a3590f9c6 |
---|---|
135 m_pending = null; | 135 m_pending = null; |
136 m_lastError = e; | 136 m_lastError = e; |
137 } | 137 } |
138 } | 138 } |
139 throw new PromiseTransientException(e); | 139 throw new PromiseTransientException(e); |
140 }, | |
141 r => { | |
142 // handle cancellation as exception | |
143 throw new OperationCanceledException("The operation has been cancelled", r); | |
144 } | 140 } |
145 ); | 141 ); |
146 | 142 |
147 m_pending = promise; | 143 m_pending = promise; |
148 } | 144 } |
192 /// <param name="stop">Stop.</param> | 188 /// <param name="stop">Stop.</param> |
193 protected virtual void StopPending(IPromise current, IDeferred stop) { | 189 protected virtual void StopPending(IPromise current, IDeferred stop) { |
194 if (current == null) { | 190 if (current == null) { |
195 stop.Resolve(); | 191 stop.Resolve(); |
196 } else { | 192 } else { |
197 current.On(stop.Resolve, stop.Reject, e => stop.Resolve()); | 193 // связваем текущую операцию с операцией остановки |
194 current.On( | |
195 stop.Resolve, // если текущая операция заверщилась, то можно начинать остановку | |
196 stop.Reject, // если текущая операция дала ошибку - то все плохо, нельзя продолжать | |
197 e => stop.Resolve() // если текущая отменилась, то можно начинать остановку | |
198 ); | |
199 // посылаем текущей операции сигнал остановки | |
198 current.Cancel(); | 200 current.Cancel(); |
199 } | 201 } |
200 } | 202 } |
201 | 203 |
202 public ExecutionState State { | 204 public ExecutionState State { |