comparison 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
comparison
equal deleted inserted replaced
184:d6a8cba73acc 185:822aab37b107
75 /// будут проигнорированы. 75 /// будут проигнорированы.
76 /// </remarks> 76 /// </remarks>
77 /// <param name="error">Исключение возникшее при выполнении операции</param> 77 /// <param name="error">Исключение возникшее при выполнении операции</param>
78 /// <exception cref="InvalidOperationException">Данное обещание уже выполнено</exception> 78 /// <exception cref="InvalidOperationException">Данное обещание уже выполнено</exception>
79 protected void SetError(Exception error) { 79 protected void SetError(Exception error) {
80 while (error is PromiseTransientException)
81 error = error.InnerException;
82
83 var isCancel = error is OperationCanceledException;
84
80 if (BeginTransit()) { 85 if (BeginTransit()) {
81 if (error is OperationCanceledException) { 86 m_error = isCancel ? error.InnerException : error;
82 m_error = error.InnerException; 87 CompleteTransit(isCancel ? CANCELLED_STATE : REJECTED_STATE);
83 CompleteTransit(CANCELLED_STATE); 88
84 } else {
85 m_error = error is PromiseTransientException ? error.InnerException : error;
86 CompleteTransit(REJECTED_STATE);
87 }
88 Signal(); 89 Signal();
89 } else { 90 } else {
90 WaitTransition(); 91 WaitTransition();
91 if (m_state == SUCCEEDED_STATE) 92 if (!isCancel || m_state == SUCCEEDED_STATE)
92 throw new InvalidOperationException("The promise is already resolved"); 93 throw new InvalidOperationException("The promise is already resolved");
93 } 94 }
94 } 95 }
95 96
96 /// <summary> 97 /// <summary>