annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
1 using System;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
2
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
3 namespace Implab.Diagnostics {
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
4 public static class Extensions {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
5 public static IPromise<T> EndLogicalOperation<T>(this IPromise<T> promise) {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
6 Safe.ArgumentNotNull(promise, "promise");
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
7 var op = TraceContext.Instance.DetachLogicalOperation();
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
8
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
9 return promise.On(
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
10 x => {
109
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
11 TraceContext.Instance.EnterLogicalOperation(op,true);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
12 TraceLog.TraceInformation("promise = {0}", x);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
13 TraceLog.EndLogicalOperation();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
14 TraceContext.Instance.Leave();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
15 },
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
16 err =>{
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
17 TraceContext.Instance.EnterLogicalOperation(op,true);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
18 TraceLog.TraceError("promise died {0}", err);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
19 TraceLog.EndLogicalOperation();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
20 TraceContext.Instance.Leave();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
21 },
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
22 () => {
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
23 TraceContext.Instance.EnterLogicalOperation(op,true);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
24 TraceLog.TraceInformation("promise cancelled");
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
25 TraceLog.EndLogicalOperation();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
26 TraceContext.Instance.Leave();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
27 }
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
28 );
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
29 }
94
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
30
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
31 public static IPromise EndLogicalOperation(this IPromise promise) {
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
32 Safe.ArgumentNotNull(promise, "promise");
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
33 var op = TraceContext.Instance.DetachLogicalOperation();
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
34
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
35 return promise.On(() => {
94
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
36 TraceContext.Instance.EnterLogicalOperation(op,true);
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
37 TraceLog.EndLogicalOperation();
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
38 TraceContext.Instance.Leave();
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 109
diff changeset
39 }, PromiseEventType.All);
94
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
40 }
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
41 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
42 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
43