annotate Implab/AbstractPromise.cs @ 121:62d2f1e98c4e v2

working version of AsyncQueue and batch operations tests
author cin
date Mon, 12 Jan 2015 18:19:41 +0300
parents 2573b562e328
children f803565868a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
1 using System;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
2 using Implab.Parallels;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
3 using System.Threading;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
4 using System.Reflection;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
5
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
6 namespace Implab {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
7 public abstract class AbstractPromise<THandler> {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
8
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
9 const int UNRESOLVED_SATE = 0;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
10 const int TRANSITIONAL_STATE = 1;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
11 const int SUCCEEDED_STATE = 2;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
12 const int REJECTED_STATE = 3;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
13 const int CANCELLED_STATE = 4;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
14
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
15 int m_state;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
16 Exception m_error;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
17
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
18 readonly AsyncQueue<THandler> m_handlers = new AsyncQueue<THandler>();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
19
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
20 #region state managment
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
21 bool BeginTransit() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
22 return UNRESOLVED_SATE == Interlocked.CompareExchange(ref m_state, TRANSITIONAL_STATE, UNRESOLVED_SATE);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
23 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
24
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
25 void CompleteTransit(int state) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
26 if (TRANSITIONAL_STATE != Interlocked.CompareExchange(ref m_state, state, TRANSITIONAL_STATE))
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
27 throw new InvalidOperationException("Can't complete transition when the object isn't in the transitional state");
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
28 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
29
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
30 void WaitTransition() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
31 while (m_state == TRANSITIONAL_STATE) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
32 Thread.MemoryBarrier();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
33 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
34 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
35
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
36 protected void BeginSetResult() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
37 if (!BeginTransit()) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
38 WaitTransition();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
39 if (m_state != CANCELLED_STATE)
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
40 throw new InvalidOperationException("The promise is already resolved");
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
41 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
42 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
43
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
44 protected void EndSetResult() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
45 CompleteTransit(SUCCEEDED_STATE);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
46 OnSuccess();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
47 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
48
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
49
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
50
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
51 /// <summary>
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
52 /// Выполняет обещание, сообщая об ошибке
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
53 /// </summary>
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
54 /// <remarks>
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
55 /// Поскольку обещание должно работать в многопточной среде, при его выполнении сразу несколько потоков
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
56 /// могу вернуть ошибку, при этом только первая будет использована в качестве результата, остальные
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
57 /// будут проигнорированы.
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
58 /// </remarks>
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
59 /// <param name="error">Исключение возникшее при выполнении операции</param>
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
60 /// <exception cref="InvalidOperationException">Данное обещание уже выполнено</exception>
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
61 protected void SetError(Exception error) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
62 if (BeginTransit()) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
63 m_error = error is PromiseTransientException ? error.InnerException : error;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
64 CompleteTransit(REJECTED_STATE);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
65 OnError();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
66 } else {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
67 WaitTransition();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
68 if (m_state == SUCCEEDED_STATE)
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
69 throw new InvalidOperationException("The promise is already resolved");
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
70 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
71 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
72
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
73 /// <summary>
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
74 /// Отменяет операцию, если это возможно.
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
75 /// </summary>
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
76 /// <remarks>Для определения была ли операция отменена следует использовать свойство <see cref="IsCancelled"/>.</remarks>
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
77 protected void SetCancelled() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
78 if (BeginTransit()) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
79 CompleteTransit(CANCELLED_STATE);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
80 OnCancelled();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
81 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
82 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
83
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
84 protected abstract void SignalSuccess(THandler handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
85
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
86 protected abstract void SignalError(THandler handler, Exception error);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
87
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
88 protected abstract void SignalCancelled(THandler handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
89
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
90 void OnSuccess() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
91 THandler handler;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
92 while (m_handlers.TryDequeue(out handler))
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
93 SignalSuccess(handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
94 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
95
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
96 void OnError() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
97 THandler handler;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
98 while (m_handlers.TryDequeue(out handler))
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
99 SignalError(handler,m_error);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
100 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
101
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
102 void OnCancelled() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
103 THandler handler;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
104 while (m_handlers.TryDequeue(out handler))
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
105 SignalCancelled(handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
106 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
107
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
108 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
109
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
110 protected abstract void Listen(PromiseEventType events, Action handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
111
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
112 #region synchronization traits
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
113 protected void WaitResult(int timeout) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
114 if (!IsResolved) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
115 var lk = new object();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
116
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
117 Listen(PromiseEventType.All, () => {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
118 lock(lk) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
119 Monitor.Pulse(lk);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
120 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
121 });
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
122
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
123 lock (lk) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
124 while(!IsResolved) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
125 if(!Monitor.Wait(lk,timeout))
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
126 throw new TimeoutException();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
127 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
128 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
129
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
130 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
131 switch (m_state) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
132 case SUCCEEDED_STATE:
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
133 return;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
134 case CANCELLED_STATE:
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
135 throw new OperationCanceledException();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
136 case REJECTED_STATE:
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
137 throw new TargetInvocationException(m_error);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
138 default:
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
139 throw new ApplicationException(String.Format("Invalid promise state {0}", m_state));
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
140 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
141 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
142 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
143
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
144 #region handlers managment
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
145
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
146 protected void AddHandler(THandler handler) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
147
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
148 if (IsResolved) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
149 InvokeHandler(handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
150
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
151 } else {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
152 // the promise is in the resolved state, just invoke the handler
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
153 m_handlers.Enqueue(handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
154
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
155
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
156 if (IsResolved && m_handlers.TryDequeue(out handler))
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
157 // if the promise have been resolved while we was adding the handler to the queue
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
158 // we can't guarantee that someone is still processing it
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
159 // therefore we need to fetch a handler from the queue and execute it
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
160 // note that fetched handler may be not the one that we have added
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
161 // even we can fetch no handlers at all :)
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
162 InvokeHandler(handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
163 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
164 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
165
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
166 protected void InvokeHandler(THandler handler) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
167 switch (m_state) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
168 case SUCCEEDED_STATE:
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
169 SignalSuccess(handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
170 break;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
171 case CANCELLED_STATE:
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
172 SignalCancelled(handler);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
173 break;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
174 case REJECTED_STATE:
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
175 SignalError(handler, m_error);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
176 break;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
177 default:
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
178 throw new Exception(String.Format("Invalid promise state {0}", m_state));
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
179 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
180 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
181
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
182 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
183
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
184 #region IPromise implementation
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
185
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
186 public void Join(int timeout) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
187 WaitResult(timeout);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
188 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
189
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
190 public void Join() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
191 WaitResult(-1);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
192 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
193
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
194 public bool IsResolved {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
195 get {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
196 Thread.MemoryBarrier();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
197 return m_state > 1;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
198 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
199 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
200
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
201 public bool IsCancelled {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
202 get {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
203 Thread.MemoryBarrier();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
204 return m_state == CANCELLED_STATE;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
205 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
206 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
207
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
208 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
209
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
210 #region ICancellable implementation
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
211
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
212 public void Cancel() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
213 SetCancelled();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
214 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
215
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
216 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
217 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
218 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
219