##// END OF EJS Templates
TraceLog tests
TraceLog tests

File last commit:

r145:706fccb85524 v2
r201:d7cd7a83189a v2
Show More
AsyncPool.cs
155 lines | 4.8 KiB | text/x-csharp | CSharpLexer
cin
initial log capabilities
r35 using Implab.Diagnostics;
cin
refactoring
r25 using System;
using System.Threading;
cin
improved asyncpool usability...
r120 using System.Linq;
cin
refactoring
r25
namespace Implab.Parallels {
/// <summary>
/// Класс для распаралеливания задач.
/// </summary>
/// <remarks>
/// Используя данный класс и лямда выражения можно распараллелить
/// вычисления, для этого используется концепция обещаний.
/// </remarks>
public static class AsyncPool {
cin
initial work on interactive logger
r45 public static IPromise<T> Invoke<T>(Func<T> func) {
cin
refactoring
r25 var p = new Promise<T>();
cin
rewritten tracing
r92 var caller = TraceContext.Instance.CurrentOperation;
cin
refactoring
r25
ThreadPool.QueueUserWorkItem(param => {
cin
rewritten tracing
r92 TraceContext.Instance.EnterLogicalOperation(caller,false);
cin
refactoring
r25 try {
cin
Implemented interllocked queue...
r14 p.Resolve(func());
cin
refactoring
r25 } catch(Exception e) {
p.Reject(e);
cin
rewritten tracing
r92 } finally {
TraceContext.Instance.Leave();
}
cin
refactoring
r25 });
return p;
cin
Implemented interllocked queue...
r14 }
cin
RC: cancellation support for promises + tests
r145 public static IPromise<T> Invoke<T>(Func<ICancellationToken, T> func) {
var p = new Promise<T>();
var caller = TraceContext.Instance.CurrentOperation;
ThreadPool.QueueUserWorkItem(param => {
TraceContext.Instance.EnterLogicalOperation(caller,false);
try {
p.Resolve(func(p));
} catch(Exception e) {
p.Reject(e);
} finally {
TraceContext.Instance.Leave();
}
});
return p;
}
cin
major update, added Drain mathod to AsyncQueue class
r124 public static IPromise<T> RunThread<T>(Func<T> func) {
cin
Implemented interllocked queue...
r14 var p = new Promise<T>();
cin
rewritten tracing
r92 var caller = TraceContext.Instance.CurrentOperation;
cin
initial log capabilities
r35
cin
Implemented interllocked queue...
r14 var worker = new Thread(() => {
cin
rewritten tracing
r92 TraceContext.Instance.EnterLogicalOperation(caller,false);
cin
Implemented interllocked queue...
r14 try {
p.Resolve(func());
} catch (Exception e) {
p.Reject(e);
cin
rewritten tracing
r92 } finally {
TraceContext.Instance.Leave();
cin
Implemented interllocked queue...
r14 }
});
worker.IsBackground = true;
worker.Start();
return p;
cin
refactoring
r25 }
cin
Interactive tracing...
r48
cin
RC: cancellation support for promises + tests
r145 public static IPromise<T> RunThread<T>(Func<ICancellationToken, T> func) {
var p = new Promise<T>();
var caller = TraceContext.Instance.CurrentOperation;
var worker = new Thread(() => {
TraceContext.Instance.EnterLogicalOperation(caller,false);
try {
p.Resolve(func(p));
} catch (Exception e) {
p.Reject(e);
} finally {
TraceContext.Instance.Leave();
}
});
worker.IsBackground = true;
worker.Start();
return p;
}
cin
Interactive tracing...
r48
cin
major update, added Drain mathod to AsyncQueue class
r124 public static IPromise RunThread(Action func) {
cin
Promises rewritten, added improved version of AsyncQueue
r119 var p = new Promise();
cin
Interactive tracing...
r48
cin
rewritten tracing
r92 var caller = TraceContext.Instance.CurrentOperation;
cin
Interactive tracing...
r48
var worker = new Thread(() => {
cin
rewritten tracing
r92 TraceContext.Instance.EnterLogicalOperation(caller,false);
cin
Interactive tracing...
r48 try {
func();
p.Resolve();
} catch (Exception e) {
p.Reject(e);
cin
rewritten tracing
r92 } finally {
TraceContext.Instance.Leave();
cin
Interactive tracing...
r48 }
});
worker.IsBackground = true;
worker.Start();
return p;
}
cin
improved asyncpool usability...
r120
cin
RC: cancellation support for promises + tests
r145 public static IPromise RunThread(Action<ICancellationToken> func) {
var p = new Promise();
var caller = TraceContext.Instance.CurrentOperation;
var worker = new Thread(() => {
TraceContext.Instance.EnterLogicalOperation(caller,false);
try {
func(p);
p.Resolve();
} catch (Exception e) {
p.Reject(e);
} finally {
TraceContext.Instance.Leave();
}
});
worker.IsBackground = true;
worker.Start();
return p;
}
cin
working version of AsyncQueue and batch operations...
r121 public static IPromise[] RunThread(params Action[] func) {
cin
major update, added Drain mathod to AsyncQueue class
r124 return func.Select(f => RunThread(f)).ToArray();
cin
improved asyncpool usability...
r120 }
cin
RC: cancellation support for promises + tests
r145 public static IPromise[] RunThread(params Action<ICancellationToken>[] func) {
return func.Select(f => RunThread(f)).ToArray();
}
cin
working version of AsyncQueue and batch operations...
r121 public static IPromise<T>[] RunThread<T>(params Func<T>[] func) {
cin
major update, added Drain mathod to AsyncQueue class
r124 return func.Select(f => RunThread(f)).ToArray();
cin
improved asyncpool usability...
r120 }
cin
RC: cancellation support for promises + tests
r145
public static IPromise<T>[] RunThread<T>(params Func<ICancellationToken, T>[] func) {
return func.Select(f => RunThread(f)).ToArray();
}
cin
refactoring
r25 }
}