##// END OF EJS Templates
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler...
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler Any unhandled OperationCanceledException will cause the promise cancelation

File last commit:

r187:dd4a3590f9c6 ref20160224
r187:dd4a3590f9c6 ref20160224
Show More
FuncChainTaskBase.cs
54 lines | 1.8 KiB | text/x-csharp | CSharpLexer
/ Implab / FuncChainTaskBase.cs
cin
RC: cancellation support for promises + tests
r145 using System;
namespace Implab {
cin
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler...
r187 public class FuncChainTaskBase<TResult> : AbstractTask<TResult> {
cin
RC: cancellation support for promises + tests
r145 readonly Func<Exception, IPromise<TResult>> m_error;
readonly Func<Exception, IPromise<TResult>> m_cancel;
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
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler...
r187 if (LockCancelation())
HandleCancelInternal(reason);
cin
RC: cancellation support for promises + tests
r145 }
protected void HandleErrorInternal(Exception error) {
if (m_error != null) {
try {
cin
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler...
r187 var p = m_error(error);
p.On(SetResult, SetErrorInternal, SetCancelledInternal);
CancellationRequested(p.Cancel);
cin
RC: cancellation support for promises + tests
r145 } catch(Exception err) {
cin
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler...
r187 SetErrorInternal(err);
cin
RC: cancellation support for promises + tests
r145 }
} else {
cin
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler...
r187 SetErrorInternal(error);
cin
RC: cancellation support for promises + tests
r145 }
}
cin
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler...
r187 protected void HandleCancelInternal(Exception reason) {
if (m_cancel != null) {
try {
var p = m_cancel(reason);
p.On(SetResult, HandleErrorInternal, SetCancelledInternal);
CancellationRequested(p.Cancel);
} catch (Exception err) {
HandleErrorInternal(err);
}
} else {
HandleErrorInternal(reason ?? new OperationCanceledException());
}
cin
RC: cancellation support for promises + tests
r145 }
}
}