Mercurial > pub > ImplabNet
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 118:e046a94eecb1 | 119:2573b562e328 |
|---|---|
| 3 using System.Linq; | 3 using System.Linq; |
| 4 using System.Text; | 4 using System.Text; |
| 5 | 5 |
| 6 namespace Implab { | 6 namespace Implab { |
| 7 public interface IPromise: ICancellable { | 7 public interface IPromise: ICancellable { |
| 8 /// <summary> | |
| 9 /// Check whereather the promise has no more than one dependent promise. | |
| 10 /// </summary> | |
| 11 bool IsExclusive { | |
| 12 get; | |
| 13 } | |
| 14 | 8 |
| 15 /// <summary> | 9 /// <summary> |
| 16 /// Тип результата, получаемого через данное обещание. | 10 /// Тип результата, получаемого через данное обещание. |
| 17 /// </summary> | 11 /// </summary> |
| 18 Type PromiseType { get; } | 12 Type PromiseType { get; } |
| 25 /// <summary> | 19 /// <summary> |
| 26 /// Обещание было отменено. | 20 /// Обещание было отменено. |
| 27 /// </summary> | 21 /// </summary> |
| 28 bool IsCancelled { get; } | 22 bool IsCancelled { get; } |
| 29 | 23 |
| 24 /// <summary> | |
| 25 /// Creates a new promise dependend on the current one and resolved on | |
| 26 /// executing the specified handlers. | |
| 27 /// </summary> | |
| 28 /// <param name="success">The handler called on the successful promise completion.</param> | |
| 29 /// <param name="error">The handler is called if an error while completing the promise occurred.</param> | |
| 30 /// <param name="cancel">The handler is called in case of promise cancellation.</param> | |
| 31 /// <returns>The newly created dependant promise.</returns> | |
| 32 /// <remarks> | |
| 33 /// <para> | |
| 34 /// If the success handler is specified the dependend promise will be resolved after the handler is | |
| 35 /// executed and the dependent promise will be linked to the current one, i.e. the cancellation | |
| 36 /// of the dependent property will lead to the cancellation of the current promise. If the | |
| 37 /// success handler isn't specified the dependent promise will not be linked to and | |
| 38 /// will not be resolved after the successfull resolution of the current one. | |
| 39 /// </para> | |
| 40 /// <para> | |
| 41 /// When the error handler is specified, the exception raised during the current promise completion | |
| 42 /// will be passed to it as the parameter. If the error handler returns without raising an | |
| 43 /// exception then the dependant promise will be resolved successfully, otherwise the exception | |
| 44 /// raised by the handler will be transmitted to the dependent promise. If the handler wants | |
| 45 /// to passthrough the original exception it needs to wrap the exception with | |
| 46 /// the <see cref="PromiseTransientException"/>. | |
| 47 /// </para> | |
| 48 /// <para> | |
| 49 /// If the cancelation handler is specified and the current promise is cancelled then the dependent | |
| 50 /// promise will be resolved after the handler is executed. If the cancelation hendler raises the | |
| 51 /// exception it will be passed to the dependent promise. | |
| 52 /// </para> | |
| 53 /// </remarks> | |
| 30 IPromise Then(Action success, Action<Exception> error, Action cancel); | 54 IPromise Then(Action success, Action<Exception> error, Action cancel); |
| 31 IPromise Then(Action success, Action<Exception> error); | 55 IPromise Then(Action success, Action<Exception> error); |
| 32 IPromise Then(Action success); | 56 IPromise Then(Action success); |
| 33 | 57 |
| 34 IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error, Action cancel); | 58 IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error, Func<IPromise> cancel); |
| 35 IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error); | 59 IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error); |
| 36 IPromise Chain(Func<IPromise> chained); | 60 IPromise Chain(Func<IPromise> chained); |
| 37 | 61 |
| 38 /// <summary> | 62 /// <summary> |
| 39 /// Добавляет последнй обработчик в цепочку обещаний, не создает промежуточных обещаний. | 63 /// Adds specified listeners to the current promise. |
| 40 /// </summary> | 64 /// </summary> |
| 41 /// <param name="success">Success.</param> | 65 /// <param name="success">The handler called on the successful promise completion.</param> |
| 42 /// <param name="error">Error.</param> | 66 /// <param name="error">The handler is called if an error while completing the promise occurred.</param> |
| 43 /// <param name="cancel">Cancel.</param> | 67 /// <param name="cancel">The handler is called in case of promise cancellation.</param> |
| 44 void On(Action success, Action<Exception> error, Action cancel); | 68 /// <returns>The current promise.</returns> |
| 45 void On(Action success, Action<Exception> error); | 69 IPromise On(Action success, Action<Exception> error, Action cancel); |
| 46 void On(Action success); | 70 IPromise On(Action success, Action<Exception> error); |
| 47 void On(Action success, PromiseEventType events); | 71 IPromise On(Action success); |
| 48 | 72 |
| 73 /// <summary> | |
| 74 /// Adds specified listeners to the current promise. | |
| 75 /// </summary> | |
| 76 /// <param name="handler">The handler called on the specified events.</param> | |
| 77 /// <param name = "events">The combination of flags denoting the events for which the | |
| 78 /// handler shoud be called.</param> | |
| 79 /// <returns>The current promise.</returns> | |
| 80 IPromise On(Action handler, PromiseEventType events); | |
| 81 | |
| 82 /// <summary> | |
| 83 /// Adds the specified error handler to the current promise | |
| 84 /// and creates the new dependant promise. | |
| 85 /// </summary> | |
| 86 /// <param name="error"> | |
| 87 /// The error handler. If the error handler returns without | |
| 88 /// an error the dependant promise will be successfully resolved. | |
| 89 /// </param> | |
| 90 /// <returns> | |
| 91 /// The new dependant promise which will be resolved after the error | |
| 92 /// handler is executed. | |
| 93 /// </returns> | |
| 94 /// <remarks> | |
| 95 /// The successfull result of the current promise will be ignored. | |
| 96 /// </remarks> | |
| 49 IPromise Error(Action<Exception> error); | 97 IPromise Error(Action<Exception> error); |
| 98 | |
| 50 /// <summary> | 99 /// <summary> |
| 51 /// Обрабатывает либо ошибку, либо результат, либо отмену. | 100 /// Adds the specified cncellation handler to the current promise |
| 101 /// and creates the new dependant promise. | |
| 52 /// </summary> | 102 /// </summary> |
| 53 /// <param name="handler">Обработчик.</param> | 103 /// <returns> |
| 54 /// <remarks>После обработке ошибки, она передается дальше.</remarks> | 104 /// The new dependant promise which will be resolved after the cancellation |
| 55 /// <summary> | 105 /// handler is executed. |
| 56 /// Обрабатывает либо ошибку, либо результат, либо отмену обещания. | 106 /// </returns> |
| 57 /// </summary> | 107 /// <param name="handler"> |
| 58 /// <param name="handler">Обработчик.</param> | 108 /// The cancellation handler. |
| 59 /// <remarks>После обработке ошибки, она передается дальше.</remarks> | 109 /// </param> |
| 60 IPromise Anyway(Action handler); | 110 /// <remarks> |
| 61 /// <summary> | 111 /// If the cancellation handler is executed without an error the dependent |
| 62 /// Обработчик для регистрации отмены обещания. | 112 /// promise will be successfully resolved, otherwise the raised exception |
| 63 /// </summary> | 113 /// will be passed to the dependant promise. The successful result of the |
| 64 /// <returns>Новое обещание, связанное с текущим, выполнится после указанного обработчика.</returns> | 114 /// current promise will be ignored. |
| 65 /// <param name="handler">Обработчик события.</param> | 115 /// </remarks> |
| 66 /// <remarks>Если обработчик вызывает исключение, то оно передается обработчику ошибки, результат работы | |
| 67 /// которого будет передан связанному обещанию</remarks> | |
| 68 IPromise Cancelled(Action handler); | 116 IPromise Cancelled(Action handler); |
| 69 | 117 |
| 70 /// <summary> | 118 /// <summary> |
| 71 /// Преобразует результат обещания к заданному типу и возвращает новое обещание. | 119 /// Преобразует результат обещания к заданному типу и возвращает новое обещание. |
| 72 /// </summary> | 120 /// </summary> |
