diff Implab/Promise.cs @ 26:f0bf98e4d22c

refactoring
author cin
date Fri, 21 Feb 2014 03:15:28 +0400
parents 9bf5b23650c9
children a236cd1f0477
line wrap: on
line diff
--- a/Implab/Promise.cs	Thu Feb 06 01:08:59 2014 +0400
+++ b/Implab/Promise.cs	Fri Feb 21 03:15:28 2014 +0400
@@ -191,7 +191,7 @@
         /// This handler will recieve an operation result as a parameter.</param>
         /// <param name="error">Handles an exception that may occur during the operation.</param>
         /// <returns>The new promise chained to this one.</returns>
-        public Promise<T> Then(ResultHandler<T> success, ErrorHandler error) {
+        public IPromise<T> Then(ResultHandler<T> success, ErrorHandler error) {
             if (success == null && error == null)
                 return this;
 
@@ -225,6 +225,16 @@
             return medium;
         }
 
+        public IPromiseBase Then(Action success,ErrorHandler error)
+        {
+            return Then(x => success(), error);
+        }
+
+        public IPromiseBase Then(Action success)
+        {
+            return Then(success);
+        }
+
         /// <summary>
         /// Adds new handlers to this promise.
         /// </summary>
@@ -232,7 +242,7 @@
         /// This handler will recieve an operation result as a parameter.</param>
         /// <param name="error">Handles an exception that may occur during the operation and returns the value which will be used as the result of the operation.</param>
         /// <returns>The new promise chained to this one.</returns>
-        public Promise<T> Then(ResultHandler<T> success, ErrorHandler<T> error) {
+        public IPromise<T> Then(ResultHandler<T> success, ErrorHandler<T> error) {
             if (success == null && error == null)
                 return this;
 
@@ -266,7 +276,7 @@
         }
 
 
-        public Promise<T> Then(ResultHandler<T> success) {
+        public IPromise<T> Then(ResultHandler<T> success) {
             if (success == null)
                 return this;
 
@@ -287,8 +297,8 @@
             return medium;
         }
 
-        public Promise<T> Error(ErrorHandler error) {
-            return Then(null, error);
+        public IPromise<T> Error(ErrorHandler error) {
+            return Then((ResultHandler<T>)null, error);
         }
 
         /// <summary>
@@ -299,7 +309,7 @@
         /// </remarks>
         /// <param name="handler">The error handler which returns the result of the promise.</param>
         /// <returns>New promise.</returns>
-        public Promise<T> Error(ErrorHandler<T> handler) {
+        public IPromise<T> Error(ErrorHandler<T> handler) {
             if (handler == null)
                 return this;
 
@@ -320,7 +330,7 @@
             return medium;
         }
 
-        public Promise<T> Anyway(Action handler) {
+        public IPromise<T> Anyway(Action handler) {
             if (handler == null)
                 return this;
 
@@ -358,7 +368,7 @@
         /// <param name="error">Обработчик ошибки. Данный обработчик получит
         /// исключение возникшее при выполнении операции.</param>
         /// <returns>Новое обещание, которое будет выполнено при выполнении исходного обещания.</returns>
-        public Promise<TNew> Map<TNew>(ResultMapper<T, TNew> mapper, ErrorHandler error) {
+        public IPromise<TNew> Map<TNew>(ResultMapper<T, TNew> mapper, ErrorHandler error) {
             if (mapper == null)
                 throw new ArgumentNullException("mapper");
 
@@ -385,7 +395,7 @@
             return chained;
         }
 
-        public Promise<TNew> Map<TNew>(ResultMapper<T, TNew> mapper) {
+        public IPromise<TNew> Map<TNew>(ResultMapper<T, TNew> mapper) {
             return Map(mapper, null);
         }
 
@@ -399,7 +409,7 @@
         /// <param name="error">Обработчик ошибки. Данный обработчик получит
         /// исключение возникшее при выполнении текуещй операции.</param>
         /// <returns>Новое обещание, которое будет выполнено по окончанию указанной аснхронной операции.</returns>
-        public Promise<TNew> Chain<TNew>(ChainedOperation<T, TNew> chained, ErrorHandler error) {
+        public IPromise<TNew> Chain<TNew>(ChainedOperation<T, TNew> chained, ErrorHandler error) {
 
             // проблема в том, что на момент связывания еще не начата асинхронная операция, поэтому нужно
             // создать посредника, к которому будут подвызяваться следующие обработчики.
@@ -437,11 +447,11 @@
             return medium;
         }
 
-        public Promise<TNew> Chain<TNew>(ChainedOperation<T, TNew> chained) {
+        public IPromise<TNew> Chain<TNew>(ChainedOperation<T, TNew> chained) {
             return Chain(chained, null);
         }
 
-        public Promise<T> Cancelled(Action handler) {
+        public IPromise<T> Cancelled(Action handler) {
             AddHandler(null, null, handler);
             return this;
         }
@@ -451,7 +461,7 @@
         /// </summary>
         /// <param name="handler">The handler that will be called anyway</param>
         /// <returns>self</returns>
-        public Promise<T> Finally(Action handler) {
+        public IPromise<T> Finally(Action handler) {
             if (handler == null)
                 throw new ArgumentNullException("handler");
             AddHandler(