changeset 199:43b1017ce100 v2

Слияние с default
author cin
date Fri, 14 Oct 2016 03:33:17 +0300
parents ea485487a424 (current diff) b305c678923a (diff)
children 71e543dbe65a
files
diffstat 16 files changed, 45 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgtags	Fri Oct 14 03:33:17 2016 +0300
@@ -0,0 +1,1 @@
+f1da3afc3521e0e1631ac19e09690bc0a241841a release v2.1
--- a/Implab/AbstractPromise.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/AbstractPromise.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -27,10 +27,8 @@
                 if ((m_mask & PromiseEventType.Success) != 0 && m_handler != null) {
                     try {
                         m_handler();
-                    } catch (Exception err) {
-                        // avoid calling handler twice in case of error
-                        if (m_error != null)
-                            SignalError(err);
+                        // Analysis disable once EmptyGeneralCatchClause
+                    } catch {
                     }
                 }
             }
@@ -55,8 +53,8 @@
                 if (m_cancel != null) {
                     try {
                         m_cancel(reason);
-                    } catch (Exception err) {
-                        SignalError(err);
+                        // Analysis disable once EmptyGeneralCatchClause
+                    } catch {
                     }
                 } else if ( (m_mask & PromiseEventType.Cancelled) != 0 && m_handler != null) {
                     try {
--- a/Implab/AbstractPromiseT.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/AbstractPromiseT.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -39,16 +39,14 @@
                 if (m_success != null) {
                     try {
                         m_success(result);
-                    } catch(Exception err) {
-                        SignalError(err);
+                        // Analysis disable once EmptyGeneralCatchClause
+                    } catch {
                     }
                 } else if ((m_mask & PromiseEventType.Success) != 0 && m_handler != null) {
                     try {
                         m_handler();
-                    } catch(Exception err) {
-                        // avoid calling handler twice in case of error
-                        if (m_error != null)
-                            SignalError(err);
+                        // Analysis disable once EmptyGeneralCatchClause
+                    } catch {
                     }
                 }
             }
@@ -73,8 +71,8 @@
                 if (m_cancel != null) {
                     try {
                         m_cancel(reason);
-                    } catch (Exception err) {
-                        SignalError(err);
+                        // Analysis disable once EmptyGeneralCatchClause
+                    } catch {
                     }
                 } else if ((m_mask & PromiseEventType.Cancelled) != 0 && m_handler != null) {
                     try {
--- a/Implab/ActionChainTask.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/ActionChainTask.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -23,10 +23,8 @@
                     var p = m_task();
                     p.On(SetResult, HandleErrorInternal, HandleCancelInternal);
                     CancellationRequested(p.Cancel);
-                } catch (OperationCanceledException reason){
-                    HandleCancelInternal(reason);
                 } catch(Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             }
         }
--- a/Implab/ActionChainTaskBase.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/ActionChainTaskBase.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -36,10 +36,10 @@
                     // отдавать ли результат или подтвердить отмену (или вернуть ошибку).
                     CancellationRequested(p.Cancel);
                 } catch (Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             } else {
-                HandleErrorInternal(reason ?? new OperationCanceledException());
+                SetCancelledInternal(reason);
             }
         }
 
@@ -50,7 +50,7 @@
                     p.On(SetResult, SetErrorInternal, SetCancelledInternal);
                     CancellationRequested(p.Cancel);
                 } catch (Exception err) {
-                    SetErrorInternal(error);
+                    SetErrorInternal(err);
                 }
             } else {
                 SetErrorInternal(error);
--- a/Implab/ActionChainTaskT.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/ActionChainTaskT.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -14,10 +14,8 @@
                     var p = m_task(value);
                     p.On(SetResult, HandleErrorInternal, HandleCancelInternal);
                     CancellationRequested(p.Cancel);
-                } catch (OperationCanceledException reason) {
-                    HandleCancelInternal(reason);
                 } catch(Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             }
         }
--- a/Implab/ActionTask.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/ActionTask.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -12,10 +12,8 @@
                 try {
                     m_task();
                     SetResult();
-                } catch(OperationCanceledException reason) {
-                    HandleCancelInternal(reason);
                 } catch(Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             }
         }
--- a/Implab/ActionTaskBase.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/ActionTaskBase.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -42,10 +42,10 @@
                     m_cancel(error);
                     SetResult();
                 } catch(Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             } else {
-                HandleErrorInternal(error ?? new OperationCanceledException());
+                SetCancelledInternal(error);
             }
         }
     }
--- a/Implab/ActionTaskT.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/ActionTaskT.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -12,10 +12,8 @@
                 try {
                     m_task(value);
                     SetResult();
-                } catch(OperationCanceledException reason) {
-                    HandleCancelInternal(reason);
                 } catch(Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             }
         }
--- 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;
--- a/Implab/FuncChainTask.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/FuncChainTask.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -15,10 +15,8 @@
                     var operation = m_task();
                     operation.On(SetResult, HandleErrorInternal, HandleCancelInternal);
                     CancellationRequested(operation.Cancel);
-                } catch (OperationCanceledException reason) {
-                    HandleCancelInternal(reason);
                 } catch (Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             }
         }
--- a/Implab/FuncChainTaskBase.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/FuncChainTaskBase.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -43,10 +43,10 @@
                     p.On(SetResult, HandleErrorInternal, SetCancelledInternal);
                     CancellationRequested(p.Cancel);
                 } catch (Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             } else {
-                HandleErrorInternal(reason ?? new OperationCanceledException());
+                SetCancelledInternal(reason);
             }
         }
     }
--- a/Implab/FuncChainTaskT.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/FuncChainTaskT.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -14,10 +14,8 @@
                     var operation = m_task(value);
                     operation.On(SetResult, HandleErrorInternal, SetCancelled);
                     CancellationRequested(operation.Cancel);
-                } catch (OperationCanceledException reason) {
-                    HandleCancelInternal(reason);
                 } catch (Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             }
         }
--- a/Implab/FuncTask.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/FuncTask.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -13,10 +13,8 @@
             if (m_task != null && LockCancelation()) {
                 try {
                     SetResult(m_task());
-                } catch(OperationCanceledException reason)  {
-                    HandleCancelInternal(reason);
                 } catch(Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             }
         }
--- a/Implab/FuncTaskBase.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/FuncTaskBase.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -40,10 +40,10 @@
                 try {
                     SetResult(m_cancel(reason));
                 } catch (Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             } else {
-                HandleErrorInternal(reason ?? new OperationCanceledException());
+                SetCancelledInternal(reason);
             }
         }
 
--- a/Implab/FuncTaskT.cs	Wed May 04 12:28:08 2016 +0300
+++ b/Implab/FuncTaskT.cs	Fri Oct 14 03:33:17 2016 +0300
@@ -12,10 +12,8 @@
             if (m_task != null && LockCancelation()) {
                 try {
                     SetResult(m_task(value));
-                } catch(OperationCanceledException reason)  {
-                    HandleCancelInternal(reason);
                 } catch(Exception err) {
-                    HandleErrorInternal(err);
+                    SetErrorInternal(err);
                 }
             }
         }