Mercurial > pub > ImplabNet
comparison Implab/Parallels/AsyncPool.cs @ 35:2880242f987a diagnostics
initial log capabilities
author | cin |
---|---|
date | Mon, 14 Apr 2014 18:25:26 +0400 |
parents | 9bf5b23650c9 |
children | 313f708a50e9 |
comparison
equal
deleted
inserted
replaced
34:dabf79fde388 | 35:2880242f987a |
---|---|
1 using Implab.Diagnostics; | |
1 using System; | 2 using System; |
2 using System.Threading; | 3 using System.Threading; |
3 | 4 |
4 namespace Implab.Parallels { | 5 namespace Implab.Parallels { |
5 /// <summary> | 6 /// <summary> |
11 /// </remarks> | 12 /// </remarks> |
12 public static class AsyncPool { | 13 public static class AsyncPool { |
13 | 14 |
14 public static Promise<T> Invoke<T>(Func<T> func) { | 15 public static Promise<T> Invoke<T>(Func<T> func) { |
15 var p = new Promise<T>(); | 16 var p = new Promise<T>(); |
17 var caller = LogContext.Current; | |
16 | 18 |
17 ThreadPool.QueueUserWorkItem(param => { | 19 ThreadPool.QueueUserWorkItem(param => { |
20 Log.Transfer(caller); | |
18 try { | 21 try { |
19 p.Resolve(func()); | 22 p.Resolve(func()); |
20 } catch(Exception e) { | 23 } catch(Exception e) { |
21 p.Reject(e); | 24 p.Reject(e); |
22 } | 25 } |
26 } | 29 } |
27 | 30 |
28 public static Promise<T> InvokeNewThread<T>(Func<T> func) { | 31 public static Promise<T> InvokeNewThread<T>(Func<T> func) { |
29 var p = new Promise<T>(); | 32 var p = new Promise<T>(); |
30 | 33 |
34 var caller = LogContext.Current; | |
35 | |
31 var worker = new Thread(() => { | 36 var worker = new Thread(() => { |
37 Log.Transfer(caller); | |
32 try { | 38 try { |
33 p.Resolve(func()); | 39 p.Resolve(func()); |
34 } catch (Exception e) { | 40 } catch (Exception e) { |
35 p.Reject(e); | 41 p.Reject(e); |
36 } | 42 } |