##// END OF EJS Templates
Слияние с default
Слияние с default

File last commit:

r198:b305c678923a default
r224:1ba2127cfcd8 merge v2
Show More
ActionChainTaskBase.cs
62 lines | 2.5 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) {
cin
fixed promise chaining behavior, the error handler doesn't handle result or cancellation handlers exceptions these exceptions are propagated to the next handlers.
r196 SetErrorInternal(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 {
cin
fixed promise chaining behavior, the error handler doesn't handle result or cancellation handlers exceptions these exceptions are propagated to the next handlers.
r196 SetCancelledInternal(reason);
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) {
koff
fixed error handling for chained actions
r198 SetErrorInternal(err);
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 }
}