diff Implab/IPromise.cs @ 119:2573b562e328 v2

Promises rewritten, added improved version of AsyncQueue
author cin
date Sun, 11 Jan 2015 19:13:02 +0300
parents 5f10d54b45df
children f75cfa58e3d4
line wrap: on
line diff
--- a/Implab/IPromise.cs	Sun Dec 28 16:09:03 2014 +0300
+++ b/Implab/IPromise.cs	Sun Jan 11 19:13:02 2015 +0300
@@ -5,12 +5,6 @@
 
 namespace Implab {
     public interface IPromise: ICancellable {
-        /// <summary>
-        /// Check whereather the promise has no more than one dependent promise.
-        /// </summary>
-        bool IsExclusive {
-            get;
-        }
 
         /// <summary>
         /// Тип результата, получаемого через данное обещание.
@@ -27,44 +21,98 @@
         /// </summary>
         bool IsCancelled { get; }
 
+        /// <summary>
+        /// Creates a new promise dependend on the current one and resolved on
+        /// executing the specified handlers.
+        /// </summary>
+        /// <param name="success">The handler called on the successful promise completion.</param>
+        /// <param name="error">The handler is called if an error while completing the promise occurred.</param>
+        /// <param name="cancel">The handler is called in case of promise cancellation.</param>
+        /// <returns>The newly created dependant promise.</returns>
+        /// <remarks>
+        /// <para>
+        /// If the success handler is specified the dependend promise will be resolved after the handler is
+        /// executed and the dependent promise will be linked to the current one, i.e. the cancellation
+        /// of the dependent property will lead to the cancellation of the current promise. If the
+        /// success handler isn't specified the dependent promise will not be linked to and
+        /// will not be resolved after the successfull resolution of the current one.
+        /// </para>
+        /// <para>
+        /// When the error handler is specified, the exception raised during the current promise completion
+        /// will be passed to it as the parameter. If the error handler returns without raising an
+        /// exception then the dependant promise will be resolved successfully, otherwise the exception
+        /// raised by the handler will be transmitted to the dependent promise. If the handler wants
+        /// to passthrough the original exception it needs to wrap the exception with
+        /// the <see cref="PromiseTransientException"/>.
+        /// </para>
+        /// <para>
+        /// If the cancelation handler is specified and the current promise is cancelled then the dependent
+        /// promise will be resolved after the handler is executed. If the cancelation hendler raises the
+        /// exception it will be passed to the dependent promise.
+        /// </para>
+        /// </remarks>
         IPromise Then(Action success, Action<Exception> error, Action cancel);
         IPromise Then(Action success, Action<Exception> error);
         IPromise Then(Action success);
 
-        IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error, Action cancel);
+        IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error, Func<IPromise> cancel);
         IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error);
         IPromise Chain(Func<IPromise> chained);
 
         /// <summary>
-        /// Добавляет последнй обработчик в цепочку обещаний, не создает промежуточных обещаний.
+        /// Adds specified listeners to the current promise.
         /// </summary>
-        /// <param name="success">Success.</param>
-        /// <param name="error">Error.</param>
-        /// <param name="cancel">Cancel.</param>
-        void On(Action success, Action<Exception> error, Action cancel);
-        void On(Action success, Action<Exception> error);
-        void On(Action success);
-        void On(Action success, PromiseEventType events);
+        /// <param name="success">The handler called on the successful promise completion.</param>
+        /// <param name="error">The handler is called if an error while completing the promise occurred.</param>
+        /// <param name="cancel">The handler is called in case of promise cancellation.</param>
+        /// <returns>The current promise.</returns>
+        IPromise On(Action success, Action<Exception> error, Action cancel);
+        IPromise On(Action success, Action<Exception> error);
+        IPromise On(Action success);
 
-        IPromise Error(Action<Exception> error);
         /// <summary>
-        /// Обрабатывает либо ошибку, либо результат, либо отмену.
+        /// Adds specified listeners to the current promise.
+        /// </summary>
+        /// <param name="handler">The handler called on the specified events.</param>
+        /// <param name = "events">The combination of flags denoting the events for which the
+        /// handler shoud be called.</param>
+        /// <returns>The current promise.</returns>
+        IPromise On(Action handler, PromiseEventType events);
+
+        /// <summary>
+        /// Adds the specified error handler to the current promise
+        /// and creates the new dependant promise.
         /// </summary>
-        /// <param name="handler">Обработчик.</param>
-        /// <remarks>После обработке ошибки, она передается дальше.</remarks>
+        /// <param name="error">
+        /// The error handler. If the error handler returns without
+        /// an error the dependant promise will be successfully resolved.
+        /// </param>
+        /// <returns>
+        /// The new dependant promise which will be resolved after the error
+        /// handler is executed.
+        /// </returns>
+        /// <remarks>
+        /// The successfull result of the current promise will be ignored.
+        /// </remarks>
+        IPromise Error(Action<Exception> error);
+
         /// <summary>
-        /// Обрабатывает либо ошибку, либо результат, либо отмену обещания.
+        /// Adds the specified cncellation handler to the current promise
+        /// and creates the new dependant promise.
         /// </summary>
-        /// <param name="handler">Обработчик.</param>
-        /// <remarks>После обработке ошибки, она передается дальше.</remarks>
-        IPromise Anyway(Action handler);
-        /// <summary>
-        /// Обработчик для регистрации отмены обещания.
-        /// </summary>
-        /// <returns>Новое обещание, связанное с текущим, выполнится после указанного обработчика.</returns>
-        /// <param name="handler">Обработчик события.</param>
-        /// <remarks>Если обработчик вызывает исключение, то оно передается обработчику ошибки, результат работы
-        /// которого будет передан связанному обещанию</remarks>
+        /// <returns>
+        /// The new dependant promise which will be resolved after the cancellation
+        /// handler is executed.
+        /// </returns>
+        /// <param name="handler">
+        /// The cancellation handler.
+        /// </param>
+        /// <remarks>
+        /// If the cancellation handler is executed without an error the dependent
+        /// promise will be successfully resolved, otherwise the raised exception
+        /// will be passed to the dependant promise. The successful result of the
+        /// current promise will be ignored.
+        /// </remarks>
         IPromise Cancelled(Action handler);
 
         /// <summary>