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();
|
|
24 p.On(SetResult, HandleErrorInternal, SetCancelled);
|
|
25 CancellationRequested(p.Cancel);
|
145
|
26 } catch(Exception err) {
|
|
27 HandleErrorInternal(err);
|
|
28 }
|
|
29 }
|
|
30 }
|
|
31
|
|
32 }
|
|
33 }
|
|
34
|