##// END OF EJS Templates
Added TraceContext support to array traits
Added TraceContext support to array traits

File last commit:

r40:fe33f4e02ad5 default
r41:2fc0fbe7d58b default
Show More
AsyncPool.cs
50 lines | 1.4 KiB | text/x-csharp | CSharpLexer
cin
initial log capabilities
r35 using Implab.Diagnostics;
cin
refactoring
r25 using System;
using System.Threading;
namespace Implab.Parallels {
/// <summary>
/// Класс для распаралеливания задач.
/// </summary>
/// <remarks>
/// Используя данный класс и лямда выражения можно распараллелить
/// вычисления, для этого используется концепция обещаний.
/// </remarks>
public static class AsyncPool {
public static Promise<T> Invoke<T>(Func<T> func) {
var p = new Promise<T>();
cin
improved tracing...
r40 var caller = TraceContext.Snapshot();
cin
refactoring
r25
ThreadPool.QueueUserWorkItem(param => {
cin
improved tracing...
r40 TraceContext.Transfer(caller);
cin
refactoring
r25 try {
cin
Implemented interllocked queue...
r14 p.Resolve(func());
cin
refactoring
r25 } catch(Exception e) {
p.Reject(e);
}
});
return p;
cin
Implemented interllocked queue...
r14 }
public static Promise<T> InvokeNewThread<T>(Func<T> func) {
var p = new Promise<T>();
cin
improved tracing...
r40 var caller = TraceContext.Snapshot();
cin
initial log capabilities
r35
cin
Implemented interllocked queue...
r14 var worker = new Thread(() => {
cin
improved tracing...
r40 TraceContext.Transfer(caller);
cin
Implemented interllocked queue...
r14 try {
p.Resolve(func());
} catch (Exception e) {
p.Reject(e);
}
});
worker.IsBackground = true;
worker.Start();
return p;
cin
refactoring
r25 }
}
}