TaskManager refactoring

This commit is contained in:
Michael Schimmel
2025-06-25 15:00:51 +02:00
parent e2a262bc5a
commit 10b653e16f
13 changed files with 183 additions and 255 deletions
+10 -15
View File
@@ -25,7 +25,7 @@ type
TMycGateFuncFuture<T> = class(TMycFuture<T>)
private
FDone: TLatch.ILatch;
FDone: TState;
FResult: T;
protected
function GetValue: T; override;
@@ -74,26 +74,21 @@ constructor TMycGateFuncFuture<T>.Create(const ATaskManager: TTaskManager; const
begin
inherited Create;
FDone := TLatch.CreateLatch(1);
// Subscribe the job execution to AGate.
// The job will run when AGate notifies the subscriber returned by Run.
ATaskManager.RunTask(
AGate,
procedure
begin
try
FDone :=
ATaskManager.RunTask(
AGate,
function: TState
begin
try
Self.FResult := AProc();
except
Self.FResult := Default(T); // Set result to Default(T) on error
raise; // Re-raise for TaskFactory to handle
end;
finally
Self.FDone.Notify; // Signal that this future is done (successfully or with error)
end;
end
);
end
);
end;
destructor TMycGateFuncFuture<T>.Destroy;
@@ -103,12 +98,12 @@ end;
function TMycGateFuncFuture<T>.GetDone: TState;
begin
Result := FDone.State;
Result := FDone;
end;
function TMycGateFuncFuture<T>.GetValue: T;
begin
Assert(FDone.State.IsSet, 'Result is not yet available.');
Assert(FDone.IsSet, 'Result is not yet available.');
Result := FResult;
end;