annotate Implab/ActionChainTask.cs @ 222:98eeb63cedb2

sync
author cin
date Tue, 22 Aug 2017 09:34:47 +0300
parents 40d7fed4a09e
children eee3e49dd1ff
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 ActionChainTask : ActionChainTaskBase, IDeferred {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
5 readonly Func<IPromise> m_task;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
6
185
822aab37b107 runnable component, work in progress
cin
parents: 149
diff changeset
7 /// <summary>
822aab37b107 runnable component, work in progress
cin
parents: 149
diff changeset
8 /// Initializes a new instance of the <see cref="Implab.ActionChainTask"/> class.
822aab37b107 runnable component, work in progress
cin
parents: 149
diff changeset
9 /// </summary>
822aab37b107 runnable component, work in progress
cin
parents: 149
diff changeset
10 /// <param name="task">The operation which will be performed when the <see cref="Resolve()"/> is called.</param>
822aab37b107 runnable component, work in progress
cin
parents: 149
diff changeset
11 /// <param name="error">The error handler which will invoke when the <see cref="Reject(Exception)"/> is called or when the task fails with an error.</param>
822aab37b107 runnable component, work in progress
cin
parents: 149
diff changeset
12 /// <param name="cancel">The cancellation handler.</param>
822aab37b107 runnable component, work in progress
cin
parents: 149
diff changeset
13 /// <param name="autoCancellable">If set to <c>true</c> will automatically accept
822aab37b107 runnable component, work in progress
cin
parents: 149
diff changeset
14 /// all cancel requests before the task is started with <see cref="Resolve()"/>,
822aab37b107 runnable component, work in progress
cin
parents: 149
diff changeset
15 /// after that all requests are directed to the task.</param>
149
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
16 public ActionChainTask(Func<IPromise> task, Func<Exception, IPromise> error, Func<Exception, IPromise> cancel, bool autoCancellable) : base(error,cancel, autoCancellable) {
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
17 m_task = task;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
18 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
19
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
20 public void Resolve() {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
21 if (m_task != null && LockCancelation()) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
22 try {
149
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
23 var p = m_task();
187
dd4a3590f9c6 Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler
cin
parents: 185
diff changeset
24 p.On(SetResult, HandleErrorInternal, HandleCancelInternal);
149
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
25 CancellationRequested(p.Cancel);
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
26 } catch(Exception err) {
196
40d7fed4a09e fixed promise chaining behavior, the error handler doesn't handle result or cancellation handlers exceptions these exceptions are propagated to the next handlers.
cin
parents: 187
diff changeset
27 SetErrorInternal(err);
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
28 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
29 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
30 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
31
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
32 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
33 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
34