Fixed concurrent processing
This commit is contained in:
@@ -60,6 +60,12 @@ type
|
||||
// Used by cache to actually load an uncached file.
|
||||
function DoLoad(const FileName: string): TFuture<TArray<TArray<TDataPoint<T>>>>;
|
||||
|
||||
function ProcessChunks(
|
||||
const DataChunks: TArray<TArray<TDataPoint<T>>>;
|
||||
const Terminated: TState;
|
||||
Processor: IMycProcessor<TArray<TDataPoint<T>>>
|
||||
): TState;
|
||||
|
||||
function ProcessFile(
|
||||
FileInfo: TAuraDataFile;
|
||||
const DataFile: TFuture<TArray<TArray<TDataPoint<T>>>>;
|
||||
@@ -354,6 +360,23 @@ begin
|
||||
Result := FCachedFiles.GetOrAdd(DataFile.GetFullFileName);
|
||||
end;
|
||||
|
||||
function TAuraDataServer<T>.ProcessChunks(
|
||||
const DataChunks: TArray<TArray<TDataPoint<T>>>;
|
||||
const Terminated: TState;
|
||||
Processor: IMycProcessor<TArray<TDataPoint<T>>>
|
||||
): TState;
|
||||
begin
|
||||
var done := TLatch.CreateLatch(Length(DataChunks));
|
||||
|
||||
for var i := 0 to High(DataChunks) do
|
||||
if not Terminated.IsSet then
|
||||
Processor.ProcessData(DataChunks[i]).Signal.Subscribe(done)
|
||||
else
|
||||
done.Notify;
|
||||
|
||||
Result := done.State;
|
||||
end;
|
||||
|
||||
function TAuraDataServer<T>.ProcessFile(
|
||||
FileInfo: TAuraDataFile;
|
||||
const DataFile: TFuture<TArray<TArray<TDataPoint<T>>>>;
|
||||
@@ -374,19 +397,12 @@ begin
|
||||
function(const DataChunks: TArray<TArray<TDataPoint<T>>>): TState
|
||||
begin
|
||||
// Process each chunk, checking for termination between chunks.
|
||||
var done := TLatch.CreateLatch(Length(DataChunks));
|
||||
for var i := 0 to High(DataChunks) do
|
||||
if not cTerminated.IsSet then
|
||||
Processor.ProcessData(DataChunks[i]).Signal.Subscribe(done)
|
||||
else
|
||||
done.Notify;
|
||||
var done := ProcessChunks(DataChunks, Terminated, Processor);
|
||||
|
||||
// Move to next file (which is currently preloading) once all Processors are done
|
||||
Result :=
|
||||
TaskManager.RunTask(
|
||||
done.State,
|
||||
function: TState begin Result := ProcessFile(nextFileInfo, nextFile, cTerminated, Processor); end
|
||||
)
|
||||
TaskManager
|
||||
.RunTask(done, function: TState begin Result := ProcessFile(nextFileInfo, nextFile, cTerminated, Processor); end);
|
||||
end
|
||||
);
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user