Mercurial > pub > ImplabNet
changeset 109:1b7ebcc52e5a v2
minor fixes
author | cin |
---|---|
date | Fri, 14 Nov 2014 14:04:24 +0300 |
parents | f3bdb7ba59b9 |
children | 1a8426e6e895 |
files | Implab/Diagnostics/ConsoleTraceListener.cs Implab/Diagnostics/Extensions.cs Implab/PromiseExtensions.cs |
diffstat | 3 files changed, 30 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Implab/Diagnostics/ConsoleTraceListener.cs Tue Nov 11 18:37:35 2014 +0300 +++ b/Implab/Diagnostics/ConsoleTraceListener.cs Fri Nov 14 14:04:24 2014 +0300 @@ -26,7 +26,7 @@ msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, channel, text.content); lock (_consoleLock) { - Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1); + //Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1); Console.WriteLine(msg); } }
--- a/Implab/Diagnostics/Extensions.cs Tue Nov 11 18:37:35 2014 +0300 +++ b/Implab/Diagnostics/Extensions.cs Fri Nov 14 14:04:24 2014 +0300 @@ -4,11 +4,28 @@ Safe.ArgumentNotNull(promise, "promise"); var op = TraceContext.Instance.DetachLogicalOperation(); - return promise.Anyway(() => { - TraceContext.Instance.EnterLogicalOperation(op,true); - TraceLog.EndLogicalOperation(); - TraceContext.Instance.Leave(); - }); + return promise.Then<T>( + x => { + TraceContext.Instance.EnterLogicalOperation(op,true); + TraceLog.TraceInformation("promise = {0}", x); + TraceLog.EndLogicalOperation(); + TraceContext.Instance.Leave(); + return x; + }, + err =>{ + TraceContext.Instance.EnterLogicalOperation(op,true); + TraceLog.TraceError("promise died {0}", err); + TraceLog.EndLogicalOperation(); + TraceContext.Instance.Leave(); + throw new TransientPromiseException(err); + }, + () => { + TraceContext.Instance.EnterLogicalOperation(op,true); + TraceLog.TraceInformation("promise cancelled"); + TraceLog.EndLogicalOperation(); + TraceContext.Instance.Leave(); + } + ); } public static IPromise EndLogicalOperation(this IPromise promise) {
--- a/Implab/PromiseExtensions.cs Tue Nov 11 18:37:35 2014 +0300 +++ b/Implab/PromiseExtensions.cs Fri Nov 14 14:04:24 2014 +0300 @@ -1,5 +1,8 @@ using System.Threading; using System; +using Implab.Diagnostics; + + #if NET_4_5 using System.Threading.Tasks; #endif @@ -57,11 +60,15 @@ public static AsyncCallback AsyncCallback<T>(this Promise<T> that, Func<IAsyncResult,T> callback) { Safe.ArgumentNotNull(that, "that"); Safe.ArgumentNotNull(callback, "callback"); + var op = TraceContext.Instance.CurrentOperation; return ar => { + TraceContext.Instance.EnterLogicalOperation(op,false); try { that.Resolve(callback(ar)); } catch (Exception err) { that.Reject(err); + } finally { + TraceContext.Instance.Leave(); } }; }