using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Implab { public interface IPromise: ICancellable { /// /// Тип результата, получаемого через данное обещание. /// Type PromiseType { get; } /// /// Обещание является выполненым, либо успешно, либо с ошибкой, либо отменено. /// bool IsResolved { get; } /// /// Обещание было отменено. /// bool IsCancelled { get; } /// /// Creates a new promise dependend on the current one and resolved on /// executing the specified handlers. /// /// The handler called on the successful promise completion. /// The handler is called if an error while completing the promise occurred. /// The handler is called in case of promise cancellation. /// The newly created dependant promise. /// /// /// 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. /// /// /// 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 . /// /// /// 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. /// /// IPromise Then(Action success, Action error, Action cancel); IPromise Then(Action success, Action error); IPromise Then(Action success); IPromise Chain(Func chained, Func error, Func cancel); IPromise Chain(Func chained, Func error); IPromise Chain(Func chained); /// /// Adds specified listeners to the current promise. /// /// The handler called on the successful promise completion. /// The handler is called if an error while completing the promise occurred. /// The handler is called in case of promise cancellation. /// The current promise. IPromise On(Action success, Action error, Action cancel); IPromise On(Action success, Action error); IPromise On(Action success); /// /// Adds specified listeners to the current promise. /// /// The handler called on the specified events. /// The combination of flags denoting the events for which the /// handler shoud be called. /// The current promise. IPromise On(Action handler, PromiseEventType events); /// /// Adds the specified error handler to the current promise /// and creates the new dependant promise. /// /// /// The error handler. If the error handler returns without /// an error the dependant promise will be successfully resolved. /// /// /// The new dependant promise which will be resolved after the error /// handler is executed. /// /// /// The successfull result of the current promise will be ignored. /// IPromise Error(Action error); /// /// Adds the specified cncellation handler to the current promise /// and creates the new dependant promise. /// /// /// The new dependant promise which will be resolved after the cancellation /// handler is executed. /// /// /// The cancellation handler. /// /// /// 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. /// IPromise Cancelled(Action handler); /// /// Преобразует результат обещания к заданному типу и возвращает новое обещание. /// IPromise Cast(); /// /// Синхронизирует текущий поток с обещанием. /// void Join(); /// /// Синхронизирует текущий поток с обещанием. /// /// Время ожидания, по его истечению возникнет исключение. /// Превышено время ожидания. void Join(int timeout); } }