Mercurial > pub > ImplabNet
annotate Implab/ActionChainTask.cs @ 213:9ee78a345738 v2
Minor code changes
author | cin |
---|---|
date | Tue, 11 Apr 2017 01:35:18 +0300 |
parents | 40d7fed4a09e |
children | eee3e49dd1ff |
rev | line source |
---|---|
145 | 1 using System; |
2 | |
3 namespace Implab { | |
4 public class ActionChainTask : ActionChainTaskBase, IDeferred { | |
5 readonly Func<IPromise> m_task; | |
6 | |
185 | 7 /// <summary> |
8 /// Initializes a new instance of the <see cref="Implab.ActionChainTask"/> class. | |
9 /// </summary> | |
10 /// <param name="task">The operation which will be performed when the <see cref="Resolve()"/> is called.</param> | |
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> | |
12 /// <param name="cancel">The cancellation handler.</param> | |
13 /// <param name="autoCancellable">If set to <c>true</c> will automatically accept | |
14 /// all cancel requests before the task is started with <see cref="Resolve()"/>, | |
15 /// after that all requests are directed to the task.</param> | |
149 | 16 public ActionChainTask(Func<IPromise> task, Func<Exception, IPromise> error, Func<Exception, IPromise> cancel, bool autoCancellable) : base(error,cancel, autoCancellable) { |
145 | 17 m_task = task; |
18 } | |
19 | |
20 public void Resolve() { | |
21 if (m_task != null && LockCancelation()) { | |
22 try { | |
149 | 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 | 25 CancellationRequested(p.Cancel); |
145 | 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 | 28 } |
29 } | |
30 } | |
31 | |
32 } | |
33 } | |
34 |