annotate Implab/ActionChainTaskT.cs @ 151:ec91a6dfa5b3 v2

Added support for 'await' operator to promises
author cin
date Thu, 04 Feb 2016 02:43:05 +0300
parents eb793fbbe4ea
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<T> : ActionChainTaskBase, IDeferred<T> {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
5 readonly Func<T, 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<T, 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(T value) {
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(value);
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