Mercurial > pub > ImplabNet
comparison Implab/AbstractTaskT.cs @ 192:f1da3afc3521 release v2.1
Слияние с v2
author | cin |
---|---|
date | Fri, 22 Apr 2016 13:10:34 +0300 |
parents | dd4a3590f9c6 |
children |
comparison
equal
deleted
inserted
replaced
71:1714fd8678ef | 192:f1da3afc3521 |
---|---|
1 using System; | |
2 using System.Threading; | |
3 | |
4 namespace Implab { | |
5 public abstract class AbstractTask<T> : AbstractPromise<T> { | |
6 int m_cancelationLock; | |
7 | |
8 /// <summary> | |
9 /// Получает эксклюзивное право отмены задания, используется для отмены задания до начала его выполнения. | |
10 /// </summary> | |
11 /// <returns><c>true</c>, if cancelation was locked, <c>false</c> otherwise.</returns> | |
12 protected bool LockCancelation() { | |
13 return 0 == Interlocked.CompareExchange(ref m_cancelationLock, 1, 0); | |
14 } | |
15 | |
16 | |
17 | |
18 protected void SetErrorInternal(Exception error) { | |
19 // unwrap | |
20 while (error is PromiseTransientException && error.InnerException != null) | |
21 error = error.InnerException; | |
22 | |
23 if (error is OperationCanceledException) | |
24 SetCancelled(error); | |
25 else | |
26 SetError(error); | |
27 } | |
28 | |
29 protected void SetCancelledInternal(Exception reason) { | |
30 SetCancelled( | |
31 reason == null ? new OperationCanceledException() : reason is OperationCanceledException ? reason : new OperationCanceledException(null, reason) | |
32 ); | |
33 } | |
34 } | |
35 } | |
36 |