comparison Implab/Diagnostics/Extensions.cs @ 119:2573b562e328 v2

Promises rewritten, added improved version of AsyncQueue
author cin
date Sun, 11 Jan 2015 19:13:02 +0300
parents 1b7ebcc52e5a
children 04d4c92d0f28
comparison
equal deleted inserted replaced
118:e046a94eecb1 119:2573b562e328
1 namespace Implab.Diagnostics { 1 using System;
2
3 namespace Implab.Diagnostics {
2 public static class Extensions { 4 public static class Extensions {
3 public static IPromise<T> EndLogicalOperation<T>(this IPromise<T> promise) { 5 public static IPromise<T> EndLogicalOperation<T>(this IPromise<T> promise) {
4 Safe.ArgumentNotNull(promise, "promise"); 6 Safe.ArgumentNotNull(promise, "promise");
5 var op = TraceContext.Instance.DetachLogicalOperation(); 7 var op = TraceContext.Instance.DetachLogicalOperation();
6 8
7 return promise.Then<T>( 9 return promise.On(
8 x => { 10 x => {
9 TraceContext.Instance.EnterLogicalOperation(op,true); 11 TraceContext.Instance.EnterLogicalOperation(op,true);
10 TraceLog.TraceInformation("promise = {0}", x); 12 TraceLog.TraceInformation("promise = {0}", x);
11 TraceLog.EndLogicalOperation(); 13 TraceLog.EndLogicalOperation();
12 TraceContext.Instance.Leave(); 14 TraceContext.Instance.Leave();
13 return x;
14 }, 15 },
15 err =>{ 16 err =>{
16 TraceContext.Instance.EnterLogicalOperation(op,true); 17 TraceContext.Instance.EnterLogicalOperation(op,true);
17 TraceLog.TraceError("promise died {0}", err); 18 TraceLog.TraceError("promise died {0}", err);
18 TraceLog.EndLogicalOperation(); 19 TraceLog.EndLogicalOperation();
19 TraceContext.Instance.Leave(); 20 TraceContext.Instance.Leave();
20 throw new TransientPromiseException(err);
21 }, 21 },
22 () => { 22 () => {
23 TraceContext.Instance.EnterLogicalOperation(op,true); 23 TraceContext.Instance.EnterLogicalOperation(op,true);
24 TraceLog.TraceInformation("promise cancelled"); 24 TraceLog.TraceInformation("promise cancelled");
25 TraceLog.EndLogicalOperation(); 25 TraceLog.EndLogicalOperation();
30 30
31 public static IPromise EndLogicalOperation(this IPromise promise) { 31 public static IPromise EndLogicalOperation(this IPromise promise) {
32 Safe.ArgumentNotNull(promise, "promise"); 32 Safe.ArgumentNotNull(promise, "promise");
33 var op = TraceContext.Instance.DetachLogicalOperation(); 33 var op = TraceContext.Instance.DetachLogicalOperation();
34 34
35 return promise.Anyway(() => { 35 return promise.On(() => {
36 TraceContext.Instance.EnterLogicalOperation(op,true); 36 TraceContext.Instance.EnterLogicalOperation(op,true);
37 TraceLog.EndLogicalOperation(); 37 TraceLog.EndLogicalOperation();
38 TraceContext.Instance.Leave(); 38 TraceContext.Instance.Leave();
39 }); 39 }, PromiseEventType.All);
40 } 40 }
41 } 41 }
42 } 42 }
43 43