Mercurial > pub > ImplabNet
annotate Implab/Diagnostics/Extensions.cs @ 149:eb793fbbe4ea v2
fixed promises cancellation
author | cin |
---|---|
date | Wed, 06 May 2015 17:11:27 +0300 |
parents | f973c5df9972 |
children |
rev | line source |
---|---|
134 | 1 namespace Implab.Diagnostics { |
92 | 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 | |
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 | 9 TraceContext.Instance.EnterLogicalOperation(op,true); |
10 TraceLog.TraceInformation("promise = {0}", x); | |
11 TraceLog.EndLogicalOperation(); | |
12 TraceContext.Instance.Leave(); | |
13 }, | |
14 err =>{ | |
15 TraceContext.Instance.EnterLogicalOperation(op,true); | |
16 TraceLog.TraceError("promise died {0}", err); | |
17 TraceLog.EndLogicalOperation(); | |
18 TraceContext.Instance.Leave(); | |
19 }, | |
138
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
134
diff
changeset
|
20 reason => { |
109 | 21 TraceContext.Instance.EnterLogicalOperation(op,true); |
140 | 22 TraceLog.TraceInformation("promise cancelled {0}", reason == null ? "<no-reason>" : reason.Message); |
109 | 23 TraceLog.EndLogicalOperation(); |
24 TraceContext.Instance.Leave(); | |
25 } | |
26 ); | |
92 | 27 } |
94 | 28 |
29 public static IPromise EndLogicalOperation(this IPromise promise) { | |
30 Safe.ArgumentNotNull(promise, "promise"); | |
31 var op = TraceContext.Instance.DetachLogicalOperation(); | |
32 | |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
109
diff
changeset
|
33 return promise.On(() => { |
94 | 34 TraceContext.Instance.EnterLogicalOperation(op,true); |
35 TraceLog.EndLogicalOperation(); | |
36 TraceContext.Instance.Leave(); | |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
109
diff
changeset
|
37 }, PromiseEventType.All); |
94 | 38 } |
92 | 39 } |
40 } | |
41 |