##// END OF EJS Templates
Added tag release v2.1 for changeset f1da3afc3521
Added tag release v2.1 for changeset f1da3afc3521

File last commit:

r187:dd4a3590f9c6 ref20160224
r193:0d69c0d6de0d default
Show More
ActionChainTaskBase.cs
62 lines | 2.6 KiB | text/x-csharp | CSharpLexer
/ Implab / ActionChainTaskBase.cs
cin
RC: cancellation support for promises + tests
r145 using System;
using System.Threading;
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 ActionChainTaskBase : AbstractTask {
cin
RC: cancellation support for promises + tests
r145 readonly Func<Exception, IPromise> m_error;
readonly Func<Exception, IPromise> m_cancel;
cin
fixed promises cancellation
r149 protected ActionChainTaskBase(Func<Exception, IPromise> error, Func<Exception, IPromise> 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);
}
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);
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 } else {
HandleErrorInternal(reason ?? new OperationCanceledException());
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 HandleErrorInternal(Exception error) {
cin
RC: cancellation support for promises + tests
r145 if (m_error != null) {
try {
cin
fixed promises cancellation
r149 var p = m_error(error);
cin
Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler...
r187 p.On(SetResult, SetErrorInternal, SetCancelledInternal);
cin
fixed promises cancellation
r149 CancellationRequested(p.Cancel);
} 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(error);
cin
RC: cancellation support for promises + tests
r145 }
} else {
cin
working on cancelation and error handling
r186 SetErrorInternal(error);
}
}
cin
RC: cancellation support for promises + tests
r145 }
}