# HG changeset patch # User cin # Date 2014-02-20 23:15:28 # Node ID f0bf98e4d22c0f12bc09f61916c681801ca9e85e # Parent 9bf5b23650c9d25c3bb235cb6f2e91cd35c74da4 refactoring diff --git a/Implab/IPromise.cs b/Implab/IPromise.cs --- a/Implab/IPromise.cs +++ b/Implab/IPromise.cs @@ -7,10 +7,26 @@ namespace Implab { public interface IPromise: IPromiseBase { - + + T Join(); + + T Join(int timeout); + IPromise Then(ResultHandler success, ErrorHandler error); + IPromise Then(ResultHandler success, ErrorHandler error); + IPromise Then(ResultHandler success); + IPromise Error(ErrorHandler error); + IPromise Error(ErrorHandler error); + IPromise Map(ResultMapper mapper, ErrorHandler error); + IPromise Map(ResultMapper mapper); + IPromise Chain(ChainedOperation chained, ErrorHandler error); + IPromise Chain(ChainedOperation chained); + + IPromise Cancelled(Action handler); + IPromise Finally(Action handler); + IPromise Anyway(Action handler); } } diff --git a/Implab/IPromiseBase.cs b/Implab/IPromiseBase.cs --- a/Implab/IPromiseBase.cs +++ b/Implab/IPromiseBase.cs @@ -15,5 +15,9 @@ namespace Implab { bool IsResolved { get; } bool IsCancelled { get; } + + IPromiseBase Then(Action success,ErrorHandler error); + IPromiseBase Then(Action success); + } } diff --git a/Implab/Parallels/ArrayTraits.cs b/Implab/Parallels/ArrayTraits.cs --- a/Implab/Parallels/ArrayTraits.cs +++ b/Implab/Parallels/ArrayTraits.cs @@ -125,7 +125,7 @@ namespace Implab.Parallels { return iter.Promise; } - public static Promise ChainedMap(this TSrc[] source, ChainedOperation transform, int threads) { + public static IPromise ChainedMap(this TSrc[] source, ChainedOperation transform, int threads) { if (source == null) throw new ArgumentNullException("source"); if (transform == null) diff --git a/Implab/Promise.cs b/Implab/Promise.cs --- a/Implab/Promise.cs +++ b/Implab/Promise.cs @@ -191,7 +191,7 @@ namespace Implab { /// This handler will recieve an operation result as a parameter. /// Handles an exception that may occur during the operation. /// The new promise chained to this one. - public Promise Then(ResultHandler success, ErrorHandler error) { + public IPromise Then(ResultHandler success, ErrorHandler error) { if (success == null && error == null) return this; @@ -225,6 +225,16 @@ namespace Implab { return medium; } + public IPromiseBase Then(Action success,ErrorHandler error) + { + return Then(x => success(), error); + } + + public IPromiseBase Then(Action success) + { + return Then(success); + } + /// /// Adds new handlers to this promise. /// @@ -232,7 +242,7 @@ namespace Implab { /// This handler will recieve an operation result as a parameter. /// Handles an exception that may occur during the operation and returns the value which will be used as the result of the operation. /// The new promise chained to this one. - public Promise Then(ResultHandler success, ErrorHandler error) { + public IPromise Then(ResultHandler success, ErrorHandler error) { if (success == null && error == null) return this; @@ -266,7 +276,7 @@ namespace Implab { } - public Promise Then(ResultHandler success) { + public IPromise Then(ResultHandler success) { if (success == null) return this; @@ -287,8 +297,8 @@ namespace Implab { return medium; } - public Promise Error(ErrorHandler error) { - return Then(null, error); + public IPromise Error(ErrorHandler error) { + return Then((ResultHandler)null, error); } /// @@ -299,7 +309,7 @@ namespace Implab { /// /// The error handler which returns the result of the promise. /// New promise. - public Promise Error(ErrorHandler handler) { + public IPromise Error(ErrorHandler handler) { if (handler == null) return this; @@ -320,7 +330,7 @@ namespace Implab { return medium; } - public Promise Anyway(Action handler) { + public IPromise Anyway(Action handler) { if (handler == null) return this; @@ -358,7 +368,7 @@ namespace Implab { /// Обработчик ошибки. Данный обработчик получит /// исключение возникшее при выполнении операции. /// Новое обещание, которое будет выполнено при выполнении исходного обещания. - public Promise Map(ResultMapper mapper, ErrorHandler error) { + public IPromise Map(ResultMapper mapper, ErrorHandler error) { if (mapper == null) throw new ArgumentNullException("mapper"); @@ -385,7 +395,7 @@ namespace Implab { return chained; } - public Promise Map(ResultMapper mapper) { + public IPromise Map(ResultMapper mapper) { return Map(mapper, null); } @@ -399,7 +409,7 @@ namespace Implab { /// Обработчик ошибки. Данный обработчик получит /// исключение возникшее при выполнении текуещй операции. /// Новое обещание, которое будет выполнено по окончанию указанной аснхронной операции. - public Promise Chain(ChainedOperation chained, ErrorHandler error) { + public IPromise Chain(ChainedOperation chained, ErrorHandler error) { // проблема в том, что на момент связывания еще не начата асинхронная операция, поэтому нужно // создать посредника, к которому будут подвызяваться следующие обработчики. @@ -437,11 +447,11 @@ namespace Implab { return medium; } - public Promise Chain(ChainedOperation chained) { + public IPromise Chain(ChainedOperation chained) { return Chain(chained, null); } - public Promise Cancelled(Action handler) { + public IPromise Cancelled(Action handler) { AddHandler(null, null, handler); return this; } @@ -451,7 +461,7 @@ namespace Implab { /// /// The handler that will be called anyway /// self - public Promise Finally(Action handler) { + public IPromise Finally(Action handler) { if (handler == null) throw new ArgumentNullException("handler"); AddHandler(