Mercurial > pub > ImplabNet
changeset 26:f0bf98e4d22c
refactoring
author | cin |
---|---|
date | Fri, 21 Feb 2014 03:15:28 +0400 |
parents | 9bf5b23650c9 |
children | a236cd1f0477 |
files | Implab/IPromise.cs Implab/IPromiseBase.cs Implab/Parallels/ArrayTraits.cs Implab/Promise.cs |
diffstat | 4 files changed, 45 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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<T>: IPromiseBase { - + + T Join(); + + T Join(int timeout); + IPromise<T> Then(ResultHandler<T> success, ErrorHandler error); + IPromise<T> Then(ResultHandler<T> success, ErrorHandler<T> error); + IPromise<T> Then(ResultHandler<T> success); + IPromise<T> Error(ErrorHandler error); + IPromise<T> Error(ErrorHandler<T> error); + IPromise<T2> Map<T2>(ResultMapper<T,T2> mapper, ErrorHandler error); + IPromise<T2> Map<T2>(ResultMapper<T, T2> mapper); + IPromise<T2> Chain<T2>(ChainedOperation<T, T2> chained, ErrorHandler error); + IPromise<T2> Chain<T2>(ChainedOperation<T, T2> chained); + + IPromise<T> Cancelled(Action handler); + IPromise<T> Finally(Action handler); + IPromise<T> Anyway(Action handler); } }
--- 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); + } }
--- 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<TDst[]> ChainedMap<TSrc, TDst>(this TSrc[] source, ChainedOperation<TSrc, TDst> transform, int threads) { + public static IPromise<TDst[]> ChainedMap<TSrc, TDst>(this TSrc[] source, ChainedOperation<TSrc, TDst> transform, int threads) { if (source == null) throw new ArgumentNullException("source"); if (transform == null)
--- 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.</param> /// <param name="error">Handles an exception that may occur during the operation.</param> /// <returns>The new promise chained to this one.</returns> - public Promise<T> Then(ResultHandler<T> success, ErrorHandler error) { + public IPromise<T> Then(ResultHandler<T> 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); + } + /// <summary> /// Adds new handlers to this promise. /// </summary> @@ -232,7 +242,7 @@ /// This handler will recieve an operation result as a parameter.</param> /// <param name="error">Handles an exception that may occur during the operation and returns the value which will be used as the result of the operation.</param> /// <returns>The new promise chained to this one.</returns> - public Promise<T> Then(ResultHandler<T> success, ErrorHandler<T> error) { + public IPromise<T> Then(ResultHandler<T> success, ErrorHandler<T> error) { if (success == null && error == null) return this; @@ -266,7 +276,7 @@ } - public Promise<T> Then(ResultHandler<T> success) { + public IPromise<T> Then(ResultHandler<T> success) { if (success == null) return this; @@ -287,8 +297,8 @@ return medium; } - public Promise<T> Error(ErrorHandler error) { - return Then(null, error); + public IPromise<T> Error(ErrorHandler error) { + return Then((ResultHandler<T>)null, error); } /// <summary> @@ -299,7 +309,7 @@ /// </remarks> /// <param name="handler">The error handler which returns the result of the promise.</param> /// <returns>New promise.</returns> - public Promise<T> Error(ErrorHandler<T> handler) { + public IPromise<T> Error(ErrorHandler<T> handler) { if (handler == null) return this; @@ -320,7 +330,7 @@ return medium; } - public Promise<T> Anyway(Action handler) { + public IPromise<T> Anyway(Action handler) { if (handler == null) return this; @@ -358,7 +368,7 @@ /// <param name="error">Обработчик ошибки. Данный обработчик получит /// исключение возникшее при выполнении операции.</param> /// <returns>Новое обещание, которое будет выполнено при выполнении исходного обещания.</returns> - public Promise<TNew> Map<TNew>(ResultMapper<T, TNew> mapper, ErrorHandler error) { + public IPromise<TNew> Map<TNew>(ResultMapper<T, TNew> mapper, ErrorHandler error) { if (mapper == null) throw new ArgumentNullException("mapper"); @@ -385,7 +395,7 @@ return chained; } - public Promise<TNew> Map<TNew>(ResultMapper<T, TNew> mapper) { + public IPromise<TNew> Map<TNew>(ResultMapper<T, TNew> mapper) { return Map(mapper, null); } @@ -399,7 +409,7 @@ /// <param name="error">Обработчик ошибки. Данный обработчик получит /// исключение возникшее при выполнении текуещй операции.</param> /// <returns>Новое обещание, которое будет выполнено по окончанию указанной аснхронной операции.</returns> - public Promise<TNew> Chain<TNew>(ChainedOperation<T, TNew> chained, ErrorHandler error) { + public IPromise<TNew> Chain<TNew>(ChainedOperation<T, TNew> chained, ErrorHandler error) { // проблема в том, что на момент связывания еще не начата асинхронная операция, поэтому нужно // создать посредника, к которому будут подвызяваться следующие обработчики. @@ -437,11 +447,11 @@ return medium; } - public Promise<TNew> Chain<TNew>(ChainedOperation<T, TNew> chained) { + public IPromise<TNew> Chain<TNew>(ChainedOperation<T, TNew> chained) { return Chain(chained, null); } - public Promise<T> Cancelled(Action handler) { + public IPromise<T> Cancelled(Action handler) { AddHandler(null, null, handler); return this; } @@ -451,7 +461,7 @@ /// </summary> /// <param name="handler">The handler that will be called anyway</param> /// <returns>self</returns> - public Promise<T> Finally(Action handler) { + public IPromise<T> Finally(Action handler) { if (handler == null) throw new ArgumentNullException("handler"); AddHandler(