Mercurial > pub > ImplabNet
diff Implab/Parallels/AsyncPool.cs @ 50:f8cbe84cfdb1
Слияние с interactive logger
author | cin |
---|---|
date | Fri, 18 Apr 2014 12:37:48 +0400 |
parents | d9d794b61bb9 |
children | 790e8a997d30 |
line wrap: on
line diff
--- a/Implab/Parallels/AsyncPool.cs Wed Apr 16 19:02:58 2014 +0400 +++ b/Implab/Parallels/AsyncPool.cs Fri Apr 18 12:37:48 2014 +0400 @@ -12,12 +12,12 @@ /// </remarks> public static class AsyncPool { - public static Promise<T> Invoke<T>(Func<T> func) { + public static IPromise<T> Invoke<T>(Func<T> func) { var p = new Promise<T>(); var caller = TraceContext.Snapshot(); ThreadPool.QueueUserWorkItem(param => { - TraceContext.Transfer(caller); + TraceContext.Fork(caller); try { p.Resolve(func()); } catch(Exception e) { @@ -28,13 +28,13 @@ return p; } - public static Promise<T> InvokeNewThread<T>(Func<T> func) { + public static IPromise<T> InvokeNewThread<T>(Func<T> func) { var p = new Promise<T>(); var caller = TraceContext.Snapshot(); var worker = new Thread(() => { - TraceContext.Transfer(caller); + TraceContext.Fork(caller); try { p.Resolve(func()); } catch (Exception e) { @@ -46,5 +46,26 @@ return p; } + + + public static IPromiseBase InvokeNewThread(Action func) { + var p = new Promise<object>(); + + var caller = TraceContext.Snapshot(); + + var worker = new Thread(() => { + TraceContext.Fork(caller); + try { + func(); + p.Resolve(); + } catch (Exception e) { + p.Reject(e); + } + }); + worker.IsBackground = true; + worker.Start(); + + return p; + } } }