annotate Implab/ActionChainTask.cs @ 172:92d5278d1b10 ref20160224

Working on text scanner
author cin
date Mon, 14 Mar 2016 01:19:38 +0300
parents eb793fbbe4ea
children 822aab37b107
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
149
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
7 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
8 m_task = task;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
9 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
10
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
11 public void Resolve() {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
12 if (m_task != null && LockCancelation()) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
13 try {
149
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
14 var p = m_task();
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
15 p.On(SetResult, HandleErrorInternal, SetCancelled);
eb793fbbe4ea fixed promises cancellation
cin
parents: 145
diff changeset
16 CancellationRequested(p.Cancel);
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
17 } catch(Exception err) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
18 HandleErrorInternal(err);
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
19 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
20 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
21 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
22
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
23 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
24 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
25