diff --git a/Implab/Diagnostics/ConsoleTraceListener.cs b/Implab/Diagnostics/ConsoleTraceListener.cs --- a/Implab/Diagnostics/ConsoleTraceListener.cs +++ b/Implab/Diagnostics/ConsoleTraceListener.cs @@ -26,7 +26,7 @@ namespace Implab.Diagnostics { 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); } } diff --git a/Implab/Diagnostics/Extensions.cs b/Implab/Diagnostics/Extensions.cs --- a/Implab/Diagnostics/Extensions.cs +++ b/Implab/Diagnostics/Extensions.cs @@ -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( + 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) { diff --git a/Implab/PromiseExtensions.cs b/Implab/PromiseExtensions.cs --- a/Implab/PromiseExtensions.cs +++ b/Implab/PromiseExtensions.cs @@ -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 @@ namespace Implab { public static AsyncCallback AsyncCallback(this Promise that, Func 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(); } }; }