Mercurial > pub > ImplabNet
diff Implab/AbstractEvent.cs @ 185:822aab37b107 ref20160224
runnable component, work in progress
author | cin |
---|---|
date | Mon, 18 Apr 2016 16:41:17 +0300 |
parents | 5802131432e4 |
children | 75103928da09 |
line wrap: on
line diff
--- a/Implab/AbstractEvent.cs Sat Apr 16 03:23:26 2016 +0300 +++ b/Implab/AbstractEvent.cs Mon Apr 18 16:41:17 2016 +0300 @@ -77,18 +77,19 @@ /// <param name="error">Исключение возникшее при выполнении операции</param> /// <exception cref="InvalidOperationException">Данное обещание уже выполнено</exception> protected void SetError(Exception error) { + while (error is PromiseTransientException) + error = error.InnerException; + + var isCancel = error is OperationCanceledException; + if (BeginTransit()) { - if (error is OperationCanceledException) { - m_error = error.InnerException; - CompleteTransit(CANCELLED_STATE); - } else { - m_error = error is PromiseTransientException ? error.InnerException : error; - CompleteTransit(REJECTED_STATE); - } + m_error = isCancel ? error.InnerException : error; + CompleteTransit(isCancel ? CANCELLED_STATE : REJECTED_STATE); + Signal(); } else { WaitTransition(); - if (m_state == SUCCEEDED_STATE) + if (!isCancel || m_state == SUCCEEDED_STATE) throw new InvalidOperationException("The promise is already resolved"); } }