TaskManager refactoring
This commit is contained in:
+10
-15
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user