diff Implab/ActionChainTaskT.cs @ 192:f1da3afc3521 release v2.1

Слияние с v2
author cin
date Fri, 22 Apr 2016 13:10:34 +0300
parents dd4a3590f9c6
children 40d7fed4a09e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab/ActionChainTaskT.cs	Fri Apr 22 13:10:34 2016 +0300
@@ -0,0 +1,27 @@
+using System;
+
+namespace Implab {
+    public class ActionChainTask<T> : ActionChainTaskBase, IDeferred<T> {
+        readonly Func<T, IPromise> m_task;
+
+        public ActionChainTask(Func<T, IPromise> task, Func<Exception, IPromise> error, Func<Exception, IPromise> cancel, bool autoCancellable) : base(error,cancel, autoCancellable) {
+            m_task = task;
+        }
+
+        public void Resolve(T value) {
+            if (m_task != null && LockCancelation()) {
+                try {
+                    var p = m_task(value);
+                    p.On(SetResult, HandleErrorInternal, HandleCancelInternal);
+                    CancellationRequested(p.Cancel);
+                } catch (OperationCanceledException reason) {
+                    HandleCancelInternal(reason);
+                } catch(Exception err) {
+                    HandleErrorInternal(err);
+                }
+            }
+        }
+
+    }
+}
+