##// 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:

r196:40d7fed4a09e default
r203:4d9830a9bbb8 v2
Show More
FuncTaskBase.cs
52 lines | 1.5 KiB | text/x-csharp | CSharpLexer
using System;
namespace Implab {
public class FuncTaskBase<TResult> : AbstractTask<TResult> {
readonly Func<Exception, TResult> m_cancel;
readonly Func<Exception, TResult> m_error;
protected FuncTaskBase( Func<Exception, TResult> error, Func<Exception, TResult> cancel, bool autoCancellable) {
m_error = error;
m_cancel = cancel;
if (autoCancellable)
CancellationRequested(CancelOperation);
}
public void Reject(Exception error) {
Safe.ArgumentNotNull(error, "error");
if (LockCancelation())
HandleErrorInternal(error);
}
protected void HandleErrorInternal(Exception error) {
if (m_error != null) {
try {
SetResult(m_error(error));
} catch(Exception err) {
SetErrorInternal(err);
}
} else {
SetErrorInternal(error);
}
}
public override void CancelOperation(Exception reason) {
if (LockCancelation())
HandleCancelInternal(reason);
}
protected void HandleCancelInternal(Exception reason) {
if (m_cancel != null) {
try {
SetResult(m_cancel(reason));
} catch (Exception err) {
SetErrorInternal(err);
}
} else {
SetCancelledInternal(reason);
}
}
}
}