92
|
1 namespace Implab.Diagnostics {
|
|
2 public static class Extensions {
|
|
3 public static IPromise<T> EndLogicalOperation<T>(this IPromise<T> promise) {
|
|
4 Safe.ArgumentNotNull(promise, "promise");
|
|
5 var op = TraceContext.Instance.DetachLogicalOperation();
|
|
6
|
109
|
7 return promise.Then<T>(
|
|
8 x => {
|
|
9 TraceContext.Instance.EnterLogicalOperation(op,true);
|
|
10 TraceLog.TraceInformation("promise = {0}", x);
|
|
11 TraceLog.EndLogicalOperation();
|
|
12 TraceContext.Instance.Leave();
|
|
13 return x;
|
|
14 },
|
|
15 err =>{
|
|
16 TraceContext.Instance.EnterLogicalOperation(op,true);
|
|
17 TraceLog.TraceError("promise died {0}", err);
|
|
18 TraceLog.EndLogicalOperation();
|
|
19 TraceContext.Instance.Leave();
|
|
20 throw new TransientPromiseException(err);
|
|
21 },
|
|
22 () => {
|
|
23 TraceContext.Instance.EnterLogicalOperation(op,true);
|
|
24 TraceLog.TraceInformation("promise cancelled");
|
|
25 TraceLog.EndLogicalOperation();
|
|
26 TraceContext.Instance.Leave();
|
|
27 }
|
|
28 );
|
92
|
29 }
|
94
|
30
|
|
31 public static IPromise EndLogicalOperation(this IPromise promise) {
|
|
32 Safe.ArgumentNotNull(promise, "promise");
|
|
33 var op = TraceContext.Instance.DetachLogicalOperation();
|
|
34
|
|
35 return promise.Anyway(() => {
|
|
36 TraceContext.Instance.EnterLogicalOperation(op,true);
|
|
37 TraceLog.EndLogicalOperation();
|
|
38 TraceContext.Instance.Leave();
|
|
39 });
|
|
40 }
|
92
|
41 }
|
|
42 }
|
|
43
|