Refactoring TFuture

This commit is contained in:
Michael Schimmel
2025-06-03 13:11:59 +02:00
parent 74a7cd71e9
commit 38c9e2830d
9 changed files with 708 additions and 65 deletions
+64
View File
@@ -8,6 +8,7 @@ uses
type
IMycTaskManager = interface
// TOD Dokumentation
function CreateTask( const Gate: IMycState; const Proc: TProc ): TMycSubscription;
// Waits for the operation associated with State to complete.
@@ -21,6 +22,69 @@ type
var
TaskManager: IMycTaskManager;
procedure SetupTaskManagerMock;
implementation
uses
System.Generics.Collections;
type
TMycExecMock = class(TInterfacedObject, IMycSubscriber)
private
FProc: TProc;
public
constructor Create(const AProc: TProc);
function Notify: Boolean;
end;
TMycTaskManagerMock = class(TInterfacedObject, IMycTaskManager)
public
// IMycTaskManager
function CreateTask(const Gate: IMycState; const Proc: TProc): TMycSubscription;
procedure WaitFor(State: IMycState);
constructor Create;
end;
{ TMycExecMock }
constructor TMycExecMock.Create(const AProc: TProc);
begin
inherited Create;
FProc := AProc;
end;
function TMycExecMock.Notify: Boolean;
begin
if Assigned(FProc) then
begin
FProc();
FProc := nil;
end;
end;
{ TMycTaskManagerMock }
constructor TMycTaskManagerMock.Create;
begin
inherited Create;
end;
function TMycTaskManagerMock.CreateTask(const Gate: IMycState; const Proc: TProc): TMycSubscription;
begin
var s: IMycState := TState(Gate);
Result := s.Subscribe( TMycExecMock.Create( Proc ) );
end;
procedure TMycTaskManagerMock.WaitFor(State: IMycState);
begin
Assert( State.IsSet );
end;
procedure SetupTaskManagerMock;
begin
TaskManager := TMycTaskManagerMock.Create;
end;
end.