annotate Implab/FuncChainTaskT.cs @ 187:dd4a3590f9c6 ref20160224

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
author cin
date Tue, 19 Apr 2016 17:35:20 +0300
parents eb793fbbe4ea
children 40d7fed4a09e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
1 using System;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
2
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
3 namespace Implab {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
4 public class FuncChainTask<TArg,TResult> : FuncChainTaskBase<TResult>, IDeferred<TArg> {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
5 readonly Func<TArg, IPromise<TResult>> m_task;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
6
149
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
7 public FuncChainTask(Func<TArg, IPromise<TResult>> task, Func<Exception, IPromise<TResult>> error, Func<Exception, IPromise<TResult>> cancel, bool autoCancellable) : base(error, cancel, autoCancellable){
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
8 m_task = task;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
9 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
10
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
11 public void Resolve(TArg value) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
12 if (m_task != null && LockCancelation()) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
13 try {
149
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
14 var operation = m_task(value);
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
15 operation.On(SetResult, HandleErrorInternal, SetCancelled);
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
16 CancellationRequested(operation.Cancel);
187
dd4a3590f9c6 Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler
cin
parents: 149
diff changeset
17 } catch (OperationCanceledException reason) {
dd4a3590f9c6 Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler
cin
parents: 149
diff changeset
18 HandleCancelInternal(reason);
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
19 } catch (Exception err) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
20 HandleErrorInternal(err);
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
21 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
22 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
23 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
24 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
25 }