annotate Implab/Diagnostics/Extensions.cs @ 243:b1e0ffdf3451 v3

working on promises
author cin
date Wed, 24 Jan 2018 19:24:10 +0300
parents f973c5df9972
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
04d4c92d0f28 Improved logging
cin
parents: 119
diff changeset
1 namespace Implab.Diagnostics {
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
2 public static class Extensions {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
3 public static IPromise<T> EndLogicalOperation<T>(this IPromise<T> promise) {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
4 Safe.ArgumentNotNull(promise, "promise");
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
5 var op = TraceContext.Instance.DetachLogicalOperation();
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
6
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
7 return promise.On(
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
8 x => {
109
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
9 TraceContext.Instance.EnterLogicalOperation(op,true);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
10 TraceLog.TraceInformation("promise = {0}", x);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
11 TraceLog.EndLogicalOperation();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
12 TraceContext.Instance.Leave();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
13 },
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
14 err =>{
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
15 TraceContext.Instance.EnterLogicalOperation(op,true);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
16 TraceLog.TraceError("promise died {0}", err);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
17 TraceLog.EndLogicalOperation();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
18 TraceContext.Instance.Leave();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
19 },
138
f75cfa58e3d4 added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents: 134
diff changeset
20 reason => {
109
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
21 TraceContext.Instance.EnterLogicalOperation(op,true);
140
cin
parents: 138
diff changeset
22 TraceLog.TraceInformation("promise cancelled {0}", reason == null ? "<no-reason>" : reason.Message);
109
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
23 TraceLog.EndLogicalOperation();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
24 TraceContext.Instance.Leave();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
25 }
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
26 );
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
27 }
94
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
28
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
29 public static IPromise EndLogicalOperation(this IPromise promise) {
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
30 Safe.ArgumentNotNull(promise, "promise");
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
31 var op = TraceContext.Instance.DetachLogicalOperation();
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
32
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
33 return promise.On(() => {
94
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
34 TraceContext.Instance.EnterLogicalOperation(op,true);
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
35 TraceLog.EndLogicalOperation();
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
36 TraceContext.Instance.Leave();
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
37 }, PromiseEventType.All);
94
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
38 }
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
39 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
40 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
41