comparison Implab/Components/RunnableComponent.cs @ 186:75103928da09 ref20160224

working on cancelation and error handling
author cin
date Tue, 19 Apr 2016 00:50:14 +0300
parents 822aab37b107
children dd4a3590f9c6
comparison
equal deleted inserted replaced
185:822aab37b107 186:75103928da09
137 } 137 }
138 } 138 }
139 throw new PromiseTransientException(e); 139 throw new PromiseTransientException(e);
140 }, 140 },
141 r => { 141 r => {
142 lock(m_stateMachine) { 142 // handle cancellation as exception
143 if (m_pending == promise) {
144 Move(Commands.Fail);
145 m_pending = null;
146 m_lastError = new OperationCanceledException("The operation has been cancelled", r);
147 }
148
149 }
150 throw new OperationCanceledException("The operation has been cancelled", r); 143 throw new OperationCanceledException("The operation has been cancelled", r);
151 } 144 }
152 ); 145 );
153 146
154 m_pending = promise; 147 m_pending = promise;
199 /// <param name="stop">Stop.</param> 192 /// <param name="stop">Stop.</param>
200 protected virtual void StopPending(IPromise current, IDeferred stop) { 193 protected virtual void StopPending(IPromise current, IDeferred stop) {
201 if (current == null) { 194 if (current == null) {
202 stop.Resolve(); 195 stop.Resolve();
203 } else { 196 } else {
204 current.On(stop.Resolve, stop.Reject, stop.CancelOperation); 197 current.On(stop.Resolve, stop.Reject, e => stop.Resolve());
205 current.Cancel(); 198 current.Cancel();
206 } 199 }
207 } 200 }
208 201
209 public ExecutionState State { 202 public ExecutionState State {