IPromise.cs
135 lines
| 6.5 KiB
| text/x-csharp
|
CSharpLexer
/ Implab / IPromise.cs
|
|
r7 | using System; | ||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
|
|
r66 | namespace Implab { | ||
| public interface IPromise: ICancellable { | ||||
|
|
r26 | |||
|
|
r66 | /// <summary> | ||
| /// Тип результата, получаемого через данное обещание. | ||||
| /// </summary> | ||||
| Type PromiseType { get; } | ||||
|
|
r25 | |||
|
|
r74 | /// <summary> | ||
|
|
r99 | /// Обещание является выполненым, либо успешно, либо с ошибкой, либо отменено. | ||
|
|
r74 | /// </summary> | ||
|
|
r66 | bool IsResolved { get; } | ||
|
|
r74 | /// <summary> | ||
| /// Обещание было отменено. | ||||
| /// </summary> | ||||
|
|
r66 | bool IsCancelled { get; } | ||
|
|
r25 | |||
|
|
r119 | /// <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> | ||||
|
|
r101 | IPromise Then(Action success, Action<Exception> error, Action cancel); | ||
| IPromise Then(Action success, Action<Exception> error); | ||||
|
|
r66 | IPromise Then(Action success); | ||
|
|
r75 | |||
|
|
r119 | IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error, Func<IPromise> cancel); | ||
|
|
r101 | IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error); | ||
|
|
r96 | IPromise Chain(Func<IPromise> chained); | ||
|
|
r75 | /// <summary> | ||
|
|
r119 | /// Adds specified listeners to the current promise. | ||
|
|
r75 | /// </summary> | ||
|
|
r119 | /// <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); | ||||
|
|
r75 | |||
|
|
r74 | /// <summary> | ||
|
|
r119 | /// 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. | ||||
|
|
r74 | /// </summary> | ||
|
|
r119 | /// <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); | ||||
|
|
r74 | /// <summary> | ||
|
|
r119 | /// Adds the specified cncellation handler to the current promise | ||
| /// and creates the new dependant promise. | ||||
|
|
r74 | /// </summary> | ||
|
|
r119 | /// <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> | ||||
|
|
r66 | IPromise Cancelled(Action handler); | ||
|
|
r7 | |||
|
|
r74 | /// <summary> | ||
| /// Преобразует результат обещания к заданному типу и возвращает новое обещание. | ||||
| /// </summary> | ||||
|
|
r66 | IPromise<T> Cast<T>(); | ||
|
|
r26 | |||
|
|
r74 | /// <summary> | ||
| /// Синхронизирует текущий поток с обещанием. | ||||
| /// </summary> | ||||
|
|
r66 | void Join(); | ||
|
|
r74 | /// <summary> | ||
| /// Синхронизирует текущий поток с обещанием. | ||||
| /// </summary> | ||||
| /// <param name="timeout">Время ожидания, по его истечению возникнет исключение.</param> | ||||
| /// <exception cref="TimeoutException">Превышено время ожидания.</exception> | ||||
|
|
r66 | void Join(int timeout); | ||
|
|
r7 | |||
| } | ||||
| } | ||||
