| @@ -132,7 +132,7 namespace Implab.Test { | |||||
| 132 | ShouldThrow(() => p.Join(1000)); |
|
132 | ShouldThrow(() => p.Join(1000)); | |
| 133 | Assert.AreEqual(ExecutionState.Failed, comp.State); |
|
133 | Assert.AreEqual(ExecutionState.Failed, comp.State); | |
| 134 |
|
134 | |||
| 135 |
Assert.Is |
|
135 | Assert.IsTrue(comp.LastError is OperationCanceledException); | |
| 136 |
|
136 | |||
| 137 | comp.Dispose(); |
|
137 | comp.Dispose(); | |
| 138 | } |
|
138 | } | |
| @@ -185,7 +185,7 namespace Implab.Test { | |||||
| 185 | p.Cancel(); |
|
185 | p.Cancel(); | |
| 186 | ShouldThrow(() => p.Join(1000)); |
|
186 | ShouldThrow(() => p.Join(1000)); | |
| 187 | Assert.AreEqual(ExecutionState.Failed, comp.State); |
|
187 | Assert.AreEqual(ExecutionState.Failed, comp.State); | |
| 188 |
Assert.Is |
|
188 | Assert.IsTrue(comp.LastError is OperationCanceledException); | |
| 189 |
|
189 | |||
| 190 | comp.Dispose(); |
|
190 | comp.Dispose(); | |
| 191 | } |
|
191 | } | |
| @@ -23,10 +23,8 namespace Implab { | |||||
| 23 | var p = m_task(); |
|
23 | var p = m_task(); | |
| 24 | p.On(SetResult, HandleErrorInternal, HandleCancelInternal); |
|
24 | p.On(SetResult, HandleErrorInternal, HandleCancelInternal); | |
| 25 | CancellationRequested(p.Cancel); |
|
25 | CancellationRequested(p.Cancel); | |
| 26 | } catch (OperationCanceledException reason){ |
|
|||
| 27 | HandleCancelInternal(reason); |
|
|||
| 28 | } catch(Exception err) { |
|
26 | } catch(Exception err) { | |
| 29 |
|
|
27 | SetErrorInternal(err); | |
| 30 | } |
|
28 | } | |
| 31 | } |
|
29 | } | |
| 32 | } |
|
30 | } | |
| @@ -36,10 +36,10 namespace Implab { | |||||
| 36 | // отдавать ли результат или подтвердить отмену (или вернуть ошибку). |
|
36 | // отдавать ли результат или подтвердить отмену (или вернуть ошибку). | |
| 37 | CancellationRequested(p.Cancel); |
|
37 | CancellationRequested(p.Cancel); | |
| 38 | } catch (Exception err) { |
|
38 | } catch (Exception err) { | |
| 39 |
|
|
39 | SetErrorInternal(err); | |
| 40 | } |
|
40 | } | |
| 41 | } else { |
|
41 | } else { | |
| 42 | HandleErrorInternal(reason ?? new OperationCanceledException()); |
|
42 | SetCancelledInternal(reason); | |
| 43 | } |
|
43 | } | |
| 44 | } |
|
44 | } | |
| 45 |
|
45 | |||
| @@ -14,10 +14,8 namespace Implab { | |||||
| 14 | var p = m_task(value); |
|
14 | var p = m_task(value); | |
| 15 | p.On(SetResult, HandleErrorInternal, HandleCancelInternal); |
|
15 | p.On(SetResult, HandleErrorInternal, HandleCancelInternal); | |
| 16 | CancellationRequested(p.Cancel); |
|
16 | CancellationRequested(p.Cancel); | |
| 17 | } catch (OperationCanceledException reason) { |
|
|||
| 18 | HandleCancelInternal(reason); |
|
|||
| 19 | } catch(Exception err) { |
|
17 | } catch(Exception err) { | |
| 20 |
|
|
18 | SetErrorInternal(err); | |
| 21 | } |
|
19 | } | |
| 22 | } |
|
20 | } | |
| 23 | } |
|
21 | } | |
| @@ -12,10 +12,8 namespace Implab { | |||||
| 12 | try { |
|
12 | try { | |
| 13 | m_task(); |
|
13 | m_task(); | |
| 14 | SetResult(); |
|
14 | SetResult(); | |
| 15 | } catch(OperationCanceledException reason) { |
|
|||
| 16 | HandleCancelInternal(reason); |
|
|||
| 17 | } catch(Exception err) { |
|
15 | } catch(Exception err) { | |
| 18 |
|
|
16 | SetErrorInternal(err); | |
| 19 | } |
|
17 | } | |
| 20 | } |
|
18 | } | |
| 21 | } |
|
19 | } | |
| @@ -42,10 +42,10 namespace Implab { | |||||
| 42 | m_cancel(error); |
|
42 | m_cancel(error); | |
| 43 | SetResult(); |
|
43 | SetResult(); | |
| 44 | } catch(Exception err) { |
|
44 | } catch(Exception err) { | |
| 45 |
|
|
45 | SetErrorInternal(err); | |
| 46 | } |
|
46 | } | |
| 47 | } else { |
|
47 | } else { | |
| 48 | HandleErrorInternal(error ?? new OperationCanceledException()); |
|
48 | SetCancelledInternal(error); | |
| 49 | } |
|
49 | } | |
| 50 | } |
|
50 | } | |
| 51 | } |
|
51 | } | |
| @@ -12,10 +12,8 namespace Implab { | |||||
| 12 | try { |
|
12 | try { | |
| 13 | m_task(value); |
|
13 | m_task(value); | |
| 14 | SetResult(); |
|
14 | SetResult(); | |
| 15 | } catch(OperationCanceledException reason) { |
|
|||
| 16 | HandleCancelInternal(reason); |
|
|||
| 17 | } catch(Exception err) { |
|
15 | } catch(Exception err) { | |
| 18 |
|
|
16 | SetErrorInternal(err); | |
| 19 | } |
|
17 | } | |
| 20 | } |
|
18 | } | |
| 21 | } |
|
19 | } | |
| @@ -120,6 +120,20 namespace Implab.Components { | |||||
| 120 |
|
120 | |||
| 121 | prev = m_pending; |
|
121 | prev = m_pending; | |
| 122 |
|
122 | |||
|
|
123 | Action<Exception> errorOrCancel = e => { | |||
|
|
124 | if (e == null) | |||
|
|
125 | e = new OperationCanceledException(); | |||
|
|
126 | ||||
|
|
127 | lock (m_stateMachine) { | |||
|
|
128 | if (m_pending == promise) { | |||
|
|
129 | Move(Commands.Fail); | |||
|
|
130 | m_pending = null; | |||
|
|
131 | m_lastError = e; | |||
|
|
132 | } | |||
|
|
133 | } | |||
|
|
134 | throw new PromiseTransientException(e); | |||
|
|
135 | }; | |||
|
|
136 | ||||
| 123 | promise = task.Then( |
|
137 | promise = task.Then( | |
| 124 | () => { |
|
138 | () => { | |
| 125 | lock(m_stateMachine) { |
|
139 | lock(m_stateMachine) { | |
| @@ -128,16 +142,9 namespace Implab.Components { | |||||
| 128 | m_pending = null; |
|
142 | m_pending = null; | |
| 129 | } |
|
143 | } | |
| 130 | } |
|
144 | } | |
| 131 |
}, |
|
145 | }, | |
| 132 | lock(m_stateMachine) { |
|
146 | errorOrCancel, | |
| 133 | if (m_pending == promise) { |
|
147 | errorOrCancel | |
| 134 | Move(Commands.Fail); |
|
|||
| 135 | m_pending = null; |
|
|||
| 136 | m_lastError = e; |
|
|||
| 137 | } |
|
|||
| 138 | } |
|
|||
| 139 | throw new PromiseTransientException(e); |
|
|||
| 140 | } |
|
|||
| 141 | ); |
|
148 | ); | |
| 142 |
|
149 | |||
| 143 | m_pending = promise; |
|
150 | m_pending = promise; | |
| @@ -15,10 +15,8 namespace Implab { | |||||
| 15 | var operation = m_task(); |
|
15 | var operation = m_task(); | |
| 16 | operation.On(SetResult, HandleErrorInternal, HandleCancelInternal); |
|
16 | operation.On(SetResult, HandleErrorInternal, HandleCancelInternal); | |
| 17 | CancellationRequested(operation.Cancel); |
|
17 | CancellationRequested(operation.Cancel); | |
| 18 | } catch (OperationCanceledException reason) { |
|
|||
| 19 | HandleCancelInternal(reason); |
|
|||
| 20 | } catch (Exception err) { |
|
18 | } catch (Exception err) { | |
| 21 |
|
|
19 | SetErrorInternal(err); | |
| 22 | } |
|
20 | } | |
| 23 | } |
|
21 | } | |
| 24 | } |
|
22 | } | |
| @@ -43,10 +43,10 namespace Implab { | |||||
| 43 | p.On(SetResult, HandleErrorInternal, SetCancelledInternal); |
|
43 | p.On(SetResult, HandleErrorInternal, SetCancelledInternal); | |
| 44 | CancellationRequested(p.Cancel); |
|
44 | CancellationRequested(p.Cancel); | |
| 45 | } catch (Exception err) { |
|
45 | } catch (Exception err) { | |
| 46 |
|
|
46 | SetErrorInternal(err); | |
| 47 | } |
|
47 | } | |
| 48 | } else { |
|
48 | } else { | |
| 49 | HandleErrorInternal(reason ?? new OperationCanceledException()); |
|
49 | SetCancelledInternal(reason); | |
| 50 | } |
|
50 | } | |
| 51 | } |
|
51 | } | |
| 52 | } |
|
52 | } | |
| @@ -14,10 +14,8 namespace Implab { | |||||
| 14 | var operation = m_task(value); |
|
14 | var operation = m_task(value); | |
| 15 | operation.On(SetResult, HandleErrorInternal, SetCancelled); |
|
15 | operation.On(SetResult, HandleErrorInternal, SetCancelled); | |
| 16 | CancellationRequested(operation.Cancel); |
|
16 | CancellationRequested(operation.Cancel); | |
| 17 | } catch (OperationCanceledException reason) { |
|
|||
| 18 | HandleCancelInternal(reason); |
|
|||
| 19 | } catch (Exception err) { |
|
17 | } catch (Exception err) { | |
| 20 |
|
|
18 | SetErrorInternal(err); | |
| 21 | } |
|
19 | } | |
| 22 | } |
|
20 | } | |
| 23 | } |
|
21 | } | |
| @@ -13,10 +13,8 namespace Implab { | |||||
| 13 | if (m_task != null && LockCancelation()) { |
|
13 | if (m_task != null && LockCancelation()) { | |
| 14 | try { |
|
14 | try { | |
| 15 | SetResult(m_task()); |
|
15 | SetResult(m_task()); | |
| 16 | } catch(OperationCanceledException reason) { |
|
|||
| 17 | HandleCancelInternal(reason); |
|
|||
| 18 | } catch(Exception err) { |
|
16 | } catch(Exception err) { | |
| 19 |
|
|
17 | SetErrorInternal(err); | |
| 20 | } |
|
18 | } | |
| 21 | } |
|
19 | } | |
| 22 | } |
|
20 | } | |
| @@ -40,10 +40,10 namespace Implab { | |||||
| 40 | try { |
|
40 | try { | |
| 41 | SetResult(m_cancel(reason)); |
|
41 | SetResult(m_cancel(reason)); | |
| 42 | } catch (Exception err) { |
|
42 | } catch (Exception err) { | |
| 43 |
|
|
43 | SetErrorInternal(err); | |
| 44 | } |
|
44 | } | |
| 45 | } else { |
|
45 | } else { | |
| 46 | HandleErrorInternal(reason ?? new OperationCanceledException()); |
|
46 | SetCancelledInternal(reason); | |
| 47 | } |
|
47 | } | |
| 48 | } |
|
48 | } | |
| 49 |
|
49 | |||
| @@ -12,10 +12,8 namespace Implab { | |||||
| 12 | if (m_task != null && LockCancelation()) { |
|
12 | if (m_task != null && LockCancelation()) { | |
| 13 | try { |
|
13 | try { | |
| 14 | SetResult(m_task(value)); |
|
14 | SetResult(m_task(value)); | |
| 15 | } catch(OperationCanceledException reason) { |
|
|||
| 16 | HandleCancelInternal(reason); |
|
|||
| 17 | } catch(Exception err) { |
|
15 | } catch(Exception err) { | |
| 18 |
|
|
16 | SetErrorInternal(err); | |
| 19 | } |
|
17 | } | |
| 20 | } |
|
18 | } | |
| 21 | } |
|
19 | } | |
General Comments 0
You need to be logged in to leave comments.
Login now
