comparison Implab/ActionChainTask.cs @ 190:1c2a16d071a7 v2

Слияние с ref20160224
author cin
date Fri, 22 Apr 2016 13:08:08 +0300
parents dd4a3590f9c6
children 40d7fed4a09e
comparison
equal deleted inserted replaced
161:2a8466f0cb8a 190:1c2a16d071a7
2 2
3 namespace Implab { 3 namespace Implab {
4 public class ActionChainTask : ActionChainTaskBase, IDeferred { 4 public class ActionChainTask : ActionChainTaskBase, IDeferred {
5 readonly Func<IPromise> m_task; 5 readonly Func<IPromise> m_task;
6 6
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>
7 public ActionChainTask(Func<IPromise> task, Func<Exception, IPromise> error, Func<Exception, IPromise> cancel, bool autoCancellable) : base(error,cancel, autoCancellable) { 16 public ActionChainTask(Func<IPromise> task, Func<Exception, IPromise> error, Func<Exception, IPromise> cancel, bool autoCancellable) : base(error,cancel, autoCancellable) {
8 m_task = task; 17 m_task = task;
9 } 18 }
10 19
11 public void Resolve() { 20 public void Resolve() {
12 if (m_task != null && LockCancelation()) { 21 if (m_task != null && LockCancelation()) {
13 try { 22 try {
14 var p = m_task(); 23 var p = m_task();
15 p.On(SetResult, HandleErrorInternal, SetCancelled); 24 p.On(SetResult, HandleErrorInternal, HandleCancelInternal);
16 CancellationRequested(p.Cancel); 25 CancellationRequested(p.Cancel);
26 } catch (OperationCanceledException reason){
27 HandleCancelInternal(reason);
17 } catch(Exception err) { 28 } catch(Exception err) {
18 HandleErrorInternal(err); 29 HandleErrorInternal(err);
19 } 30 }
20 } 31 }
21 } 32 }