##// END OF EJS Templates
fixed DFA optimization, JSON is fully functional
fixed DFA optimization, JSON is fully functional

File last commit:

r149:eb793fbbe4ea v2
r183:4f82e0f161c3 ref20160224
Show More
FuncChainTaskBase.cs
58 lines | 1.8 KiB | text/x-csharp | CSharpLexer
/ Implab / FuncChainTaskBase.cs
cin
RC: cancellation support for promises + tests
r145 using System;
using System.Threading;
namespace Implab {
public class FuncChainTaskBase<TResult> : AbstractPromise<TResult> {
readonly Func<Exception, IPromise<TResult>> m_error;
readonly Func<Exception, IPromise<TResult>> m_cancel;
int m_cancelationLock;
cin
fixed promises cancellation
r149 protected FuncChainTaskBase( Func<Exception, IPromise<TResult>> error, Func<Exception, IPromise<TResult>> cancel, bool autoCancellable) {
cin
RC: cancellation support for promises + tests
r145 m_error = error;
m_cancel = cancel;
cin
fixed promises cancellation
r149 if (autoCancellable)
CancellationRequested(CancelOperation);
cin
RC: cancellation support for promises + tests
r145 }
public void Reject(Exception error) {
if (LockCancelation())
HandleErrorInternal(error);
}
public override void CancelOperation(Exception reason) {
cin
fixed promises cancellation
r149 if (LockCancelation()) {
if (m_cancel != null) {
try {
m_cancel(reason).On(SetResult, HandleErrorInternal, SetCancelled);
} catch (Exception err) {
HandleErrorInternal(err);
}
} else {
SetCancelled(reason);
cin
RC: cancellation support for promises + tests
r145 }
}
}
protected void HandleErrorInternal(Exception error) {
if (m_error != null) {
try {
cin
fixed promises cancellation
r149 var operation = m_error(error);
operation.On(SetResult, SetError, SetCancelled);
CancellationRequested(operation.Cancel);
cin
RC: cancellation support for promises + tests
r145 } catch(Exception err) {
SetError(err);
}
} else {
SetError(error);
}
}
protected bool LockCancelation() {
return 0 == Interlocked.CompareExchange(ref m_cancelationLock, 1, 0);
}
}
}