annotate Implab/ActionChainTask.cs @ 186:75103928da09 ref20160224

working on cancelation and error handling
author cin
date Tue, 19 Apr 2016 00:50:14 +0300
parents 822aab37b107
children dd4a3590f9c6
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();
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
24 p.On(SetResult, HandleErrorInternal, SetCancelled);
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) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
27 HandleErrorInternal(err);
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