Refactoring TFuture
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user