comparison Implab/AbstractEvent.cs @ 190:1c2a16d071a7 v2

Слияние с ref20160224
author cin
date Fri, 22 Apr 2016 13:08:08 +0300
parents 75103928da09
children d6fe09f5592c
comparison
equal deleted inserted replaced
161:2a8466f0cb8a 190:1c2a16d071a7
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 if (BeginTransit()) { 80 if (BeginTransit()) {
81 if (error is OperationCanceledException) { 81 m_error = error;
82 m_error = error.InnerException; 82 CompleteTransit(REJECTED_STATE);
83 CompleteTransit(CANCELLED_STATE); 83
84 } else {
85 m_error = error is PromiseTransientException ? error.InnerException : error;
86 CompleteTransit(REJECTED_STATE);
87 }
88 Signal(); 84 Signal();
89 } else { 85 } else {
90 WaitTransition(); 86 WaitTransition();
91 if (m_state == SUCCEEDED_STATE) 87 if (m_state == SUCCEEDED_STATE)
92 throw new InvalidOperationException("The promise is already resolved"); 88 throw new InvalidOperationException("The promise is already resolved");
137 133
138 switch (m_state) { 134 switch (m_state) {
139 case SUCCEEDED_STATE: 135 case SUCCEEDED_STATE:
140 return; 136 return;
141 case CANCELLED_STATE: 137 case CANCELLED_STATE:
142 throw new OperationCanceledException(); 138 throw new OperationCanceledException("The operation has been cancelled", m_error);
143 case REJECTED_STATE: 139 case REJECTED_STATE:
144 throw new TargetInvocationException(m_error); 140 throw new TargetInvocationException(m_error);
145 default: 141 default:
146 throw new ApplicationException(String.Format("Invalid promise state {0}", m_state)); 142 throw new ApplicationException(String.Format("The promise state {0} is invalid", m_state));
147 } 143 }
148 } 144 }
149 #endregion 145 #endregion
150 146
151 #region handlers managment 147 #region handlers managment