diff Implab/Components/RunnableComponent.cs @ 199:43b1017ce100 v2

Слияние с default
author cin
date Fri, 14 Oct 2016 03:33:17 +0300
parents 40d7fed4a09e
children 2651cb9a4250
line wrap: on
line diff
--- a/Implab/Components/RunnableComponent.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/Components/RunnableComponent.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -120,6 +120,20 @@
             
                 prev = m_pending;
 
+                Action<Exception> errorOrCancel = e => {
+                    if (e == null)
+                        e = new OperationCanceledException();
+                    
+                    lock (m_stateMachine) {
+                        if (m_pending == promise) {
+                            Move(Commands.Fail);
+                            m_pending = null;
+                            m_lastError = e;
+                        }
+                    }
+                    throw new PromiseTransientException(e);
+                };
+
                 promise = task.Then(
                     () => {
                         lock(m_stateMachine) {
@@ -128,16 +142,9 @@
                                 m_pending = null;
                             }
                         }
-                    }, e => {
-                        lock(m_stateMachine) {
-                            if (m_pending == promise) {
-                                Move(Commands.Fail);
-                                m_pending = null;
-                                m_lastError = e;
-                            }
-                        }
-                        throw new PromiseTransientException(e);
-                    }
+                    },
+                    errorOrCancel,
+                    errorOrCancel 
                 );
 
                 m_pending = promise;