Fixed concurrent processing

This commit is contained in:
Michael Schimmel
2025-07-16 14:12:07 +02:00
parent bc75f08477
commit 342eb07c42
8 changed files with 192 additions and 105 deletions
+27
View File
@@ -82,9 +82,13 @@ type
class operator Implicit(const A: TConverter<S, T>): IConverter; overload;
class function CreateGeneric(const Func: TConstFunc<S, T>): TConverter<S, T>; static;
class function CreateParallel(const Func: TConstFunc<S, T>): TConverter<S, T>; static;
function Chain<R>(const Next: TConverter<T, R>): TConverter<T, R>; overload; inline;
function Chain<R>(const Func: TConstFunc<T, R>): TConverter<T, R>; overload; inline;
function ChainParallel<R>(const Func: TConstFunc<T, R>): TConverter<T, R>; overload; inline;
function MakeParallel: TConverter<T, T>; overload; inline;
// Extracts the field of a record by it's name (using RTTI).
function Field<R>(const FieldName: String): TConverter<T, R>; overload; inline;
@@ -112,6 +116,8 @@ type
class function CreateDataPointConverter<S, T>(const Func: TConstFunc<S, T>): TConverter<TDataPoint<S>, TDataPoint<T>>; static;
class function CreateSequence<T>(Count: Integer; const Parent: TDataProvider<T>): TArray<TConverter<T, T>>; overload; static;
class function Parallel<T>(Parent: TDataProvider<T>): TConverter<T, T>; static;
end;
implementation
@@ -184,11 +190,21 @@ begin
Result := Chain<R>(TMycGenericConverter<T, R>.Create(Func));
end;
function TConverter<S, T>.ChainParallel<R>(const Func: TConstFunc<T, R>): TConverter<T, R>;
begin
Result := Chain<R>(TMycGenericParallelConverter<T, R>.Create(Func));
end;
class function TConverter<S, T>.CreateGeneric(const Func: TConstFunc<S, T>): TConverter<S, T>;
begin
Result := TMycGenericConverter<S, T>.Create(Func);
end;
class function TConverter<S, T>.CreateParallel(const Func: TConstFunc<S, T>): TConverter<S, T>;
begin
Result := TMycGenericParallelConverter<S, T>.Create(Func);
end;
function TConverter<S, T>.Field<R>(const FieldName: String): TConverter<T, R>;
begin
Result := Chain<R>(TConverter.CreateRecordField<T, R>(FieldName));
@@ -199,6 +215,11 @@ begin
Result := FConverter.Sender;
end;
function TConverter<S, T>.MakeParallel: TConverter<T, T>;
begin
Result := Chain<T>(TMycGenericParallelConverter<T, T>.Create(function(const Value: T): T begin Result := Value; end));
end;
function TConverter<S, T>.Sequence(Count: Integer): IMycDataSequence<T>;
begin
Result := TMycSequence<T>.Create(Count);
@@ -288,4 +309,10 @@ begin
Parent.Link(seq);
end;
class function TConverter.Parallel<T>(Parent: TDataProvider<T>): TConverter<T, T>;
begin
Result := TMycParallelConverter<T>.Create;
Parent.Link(Result);
end;
end.