# HG changeset patch # User cin # Date 1392938128 -14400 # Node ID f0bf98e4d22c0f12bc09f61916c681801ca9e85e # Parent 9bf5b23650c9d25c3bb235cb6f2e91cd35c74da4 refactoring diff -r 9bf5b23650c9 -r f0bf98e4d22c Implab/IPromise.cs --- a/Implab/IPromise.cs Thu Feb 06 01:08:59 2014 +0400 +++ b/Implab/IPromise.cs Fri Feb 21 03:15:28 2014 +0400 @@ -7,10 +7,26 @@ { 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 -r 9bf5b23650c9 -r f0bf98e4d22c Implab/IPromiseBase.cs --- a/Implab/IPromiseBase.cs Thu Feb 06 01:08:59 2014 +0400 +++ b/Implab/IPromiseBase.cs Fri Feb 21 03:15:28 2014 +0400 @@ -15,5 +15,9 @@ bool IsResolved { get; } bool IsCancelled { get; } + + IPromiseBase Then(Action success,ErrorHandler error); + IPromiseBase Then(Action success); + } } diff -r 9bf5b23650c9 -r f0bf98e4d22c Implab/Parallels/ArrayTraits.cs --- a/Implab/Parallels/ArrayTraits.cs Thu Feb 06 01:08:59 2014 +0400 +++ b/Implab/Parallels/ArrayTraits.cs Fri Feb 21 03:15:28 2014 +0400 @@ -125,7 +125,7 @@ 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 -r 9bf5b23650c9 -r f0bf98e4d22c Implab/Promise.cs --- a/Implab/Promise.cs Thu Feb 06 01:08:59 2014 +0400 +++ b/Implab/Promise.cs Fri Feb 21 03:15:28 2014 +0400 @@ -191,7 +191,7 @@ /// 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 @@ 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 @@ /// 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 @@ } - public Promise Then(ResultHandler success) { + public IPromise Then(ResultHandler success) { if (success == null) return this; @@ -287,8 +297,8 @@ 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 @@ /// /// 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 @@ return medium; } - public Promise Anyway(Action handler) { + public IPromise Anyway(Action handler) { if (handler == null) return this; @@ -358,7 +368,7 @@ /// Обработчик ошибки. Данный обработчик получит /// исключение возникшее при выполнении операции. /// Новое обещание, которое будет выполнено при выполнении исходного обещания. - 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 @@ return chained; } - public Promise Map(ResultMapper mapper) { + public IPromise Map(ResultMapper mapper) { return Map(mapper, null); } @@ -399,7 +409,7 @@ /// Обработчик ошибки. Данный обработчик получит /// исключение возникшее при выполнении текуещй операции. /// Новое обещание, которое будет выполнено по окончанию указанной аснхронной операции. - public Promise Chain(ChainedOperation chained, ErrorHandler error) { + public IPromise Chain(ChainedOperation chained, ErrorHandler error) { // проблема в том, что на момент связывания еще не начата асинхронная операция, поэтому нужно // создать посредника, к которому будут подвызяваться следующие обработчики. @@ -437,11 +447,11 @@ 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 @@ /// /// 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(