comparison Implab/AbstractPromise.cs @ 130:671f60cd0250 v2

fixed Resove method bug when calling it on already cancelled promise
author cin
date Fri, 30 Jan 2015 17:07:17 +0300
parents f803565868a4
children f75cfa58e3d4
comparison
equal deleted inserted replaced
129:471f596b2603 130:671f60cd0250
37 while (m_state == TRANSITIONAL_STATE) { 37 while (m_state == TRANSITIONAL_STATE) {
38 Thread.MemoryBarrier(); 38 Thread.MemoryBarrier();
39 } 39 }
40 } 40 }
41 41
42 protected void BeginSetResult() { 42 protected bool BeginSetResult() {
43 if (!BeginTransit()) { 43 if (!BeginTransit()) {
44 WaitTransition(); 44 WaitTransition();
45 if (m_state != CANCELLED_STATE) 45 if (m_state != CANCELLED_STATE)
46 throw new InvalidOperationException("The promise is already resolved"); 46 throw new InvalidOperationException("The promise is already resolved");
47 } 47 return false;
48 }
49 return true;
48 } 50 }
49 51
50 protected void EndSetResult() { 52 protected void EndSetResult() {
51 CompleteTransit(SUCCEEDED_STATE); 53 CompleteTransit(SUCCEEDED_STATE);
52 OnSuccess(); 54 OnSuccess();