Mercurial > pub > ImplabNet
comparison Implab/Components/RunnableComponent.cs @ 196:40d7fed4a09e
fixed promise chaining behavior, the error handler doesn't handle result or cancellation handlers exceptions these exceptions are propagated to the next handlers.
| author | cin |
|---|---|
| date | Mon, 29 Aug 2016 23:15:51 +0300 |
| parents | dd4a3590f9c6 |
| children | 2651cb9a4250 |
comparison
equal
deleted
inserted
replaced
| 193:0d69c0d6de0d | 196:40d7fed4a09e |
|---|---|
| 118 lock (m_stateMachine) { | 118 lock (m_stateMachine) { |
| 119 Move(cmd); | 119 Move(cmd); |
| 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) { |
| 126 if (m_pending == promise) { | 140 if (m_pending == promise) { |
| 127 Move(Commands.Ok); | 141 Move(Commands.Ok); |
| 128 m_pending = null; | 142 m_pending = null; |
| 129 } | 143 } |
| 130 } | 144 } |
| 131 }, e => { | 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; |
| 144 } | 151 } |
| 145 | 152 |
