##// END OF EJS Templates
Added 'Fail' method to RunnableComponent which allows component to move from...
Added 'Fail' method to RunnableComponent which allows component to move from Running to Failed state. Added PollingComponent a timer based runnable component More tests Added FailPromise a thin class to wrap exceptions Fixed error handling in SuccessPromise classes.

File last commit:

r187:dd4a3590f9c6 ref20160224
r203:4d9830a9bbb8 v2
Show More
AbstractTaskT.cs
36 lines | 1.3 KiB | text/x-csharp | CSharpLexer
using System;
using System.Threading;
namespace Implab {
public abstract class AbstractTask<T> : AbstractPromise<T> {
int m_cancelationLock;
/// <summary>
/// Получает эксклюзивное право отмены задания, используется для отмены задания до начала его выполнения.
/// </summary>
/// <returns><c>true</c>, if cancelation was locked, <c>false</c> otherwise.</returns>
protected bool LockCancelation() {
return 0 == Interlocked.CompareExchange(ref m_cancelationLock, 1, 0);
}
protected void SetErrorInternal(Exception error) {
// unwrap
while (error is PromiseTransientException && error.InnerException != null)
error = error.InnerException;
if (error is OperationCanceledException)
SetCancelled(error);
else
SetError(error);
}
protected void SetCancelledInternal(Exception reason) {
SetCancelled(
reason == null ? new OperationCanceledException() : reason is OperationCanceledException ? reason : new OperationCanceledException(null, reason)
);
}
}
}