Moved signal interfaces inside records

This commit is contained in:
Michael Schimmel
2025-06-05 23:27:48 +02:00
parent 7ba42b0c7c
commit a57b2d50e4
15 changed files with 316 additions and 313 deletions
+21 -21
View File
@@ -16,9 +16,9 @@ type
// Helper class to notify a latch when its Notify method is called.
TLatchNotifierSubscriber = class(TInterfacedObject, IMycSubscriber)
private
FGateLatch: IMycLatch;
FGateLatch: TLatch.ILatch;
public
constructor Create(AGateLatch: IMycLatch);
constructor Create(AGateLatch: TLatch.ILatch);
// IMycSubscriber
function Notify: Boolean; // Implements IMycSubscriber.Notify [cite: 46, 181, 299]
end;
@@ -54,7 +54,7 @@ implementation
{ TLatchNotifierSubscriber }
constructor TLatchNotifierSubscriber.Create(AGateLatch: IMycLatch);
constructor TLatchNotifierSubscriber.Create(AGateLatch: TLatch.ILatch);
begin
inherited Create;
FGateLatch := AGateLatch;
@@ -89,8 +89,8 @@ end;
procedure TTestMycGateFuncFuture.Test_BasicSuccess_WithImmediateInitState;
var
LFuture: IMycFuture<Integer>;
LInitStateAsState: IMycState; // Parameter for Create
LFuture: TFuture<Integer>.IFuture;
LInitStateAsState: TState.IState; // Parameter for Create
LResultValue: Integer;
const
CExpectedResult = 42;
@@ -109,19 +109,19 @@ begin
end
);
FTaskFactory.WaitFor(LFuture.Done); // Accesses IMycFuture.GetDone [cite: 110, 234, 352]
FTaskFactory.WaitFor(LFuture.Done); // Accesses IFuture.GetDone [cite: 110, 234, 352]
Assert.IsTrue(LFuture.Done.IsSet, 'Future should be marked as done.'); // Accesses IMycState.IsSet [cite: 57, 194, 312]
Assert.IsTrue(LFuture.Done.IsSet, 'Future should be marked as done.'); // Accesses TState.IState.IsSet [cite: 57, 194, 312]
Assert.AreEqual(1, FProcExecutionCount, 'AProc should have been executed once.');
LResultValue := LFuture.GetResult; // Accesses IMycFuture.GetResult
LResultValue := LFuture.GetResult; // Accesses IFuture.GetResult
Assert.AreEqual(CExpectedResult, LResultValue, 'GetResult returned an unexpected value.');
end;
procedure TTestMycGateFuncFuture.Test_ChainedExecution_WithDelayedInitState;
var
LFuture: IMycFuture<string>;
LInitLatch: IMycLatch;
LFuture: tFuture<string>.IFuture;
LInitLatch: TLatch.ILatch;
LResultValue: string;
const
CExpectedResult = 'ChainCompleted';
@@ -155,9 +155,9 @@ end;
procedure TTestMycGateFuncFuture.Test_ExceptionInProc_HandledAsPlanned;
var
LFuture: IMycFuture<Integer>;
LFuture: TFuture<Integer>.IFuture;
LLocalTaskFactory: IMycTaskFactory;
LInitStateAsState: IMycState;
LInitStateAsState: TState.IState;
LResultValue: Integer;
LExpectedExceptionRaisedByFactory: Boolean;
const
@@ -219,8 +219,8 @@ end;
procedure TTestMycGateFuncFuture.Test_GetResult_BeforeDone_RaisesException;
var
LFuture: IMycFuture<Integer>;
LInitLatch: IMycLatch;
LFuture: TFuture<Integer>.IFuture;
LInitLatch: TLatch.ILatch;
begin
LInitLatch := TLatch.CreateLatch(1);
@@ -248,12 +248,12 @@ end;
procedure TTestMycGateFuncFuture.Test_FanIn_OneFutureWaitsForMultipleOthers;
var
LPrerequisiteFuture1, LPrerequisiteFuture2: IMycFuture<Integer>;
LMainFuture: IMycFuture<string>;
LGateLatch: IMycLatch;
LPrerequisiteFuture1, LPrerequisiteFuture2: TFuture<Integer>.IFuture;
LMainFuture: TFuture<string>.IFuture;
LGateLatch: TLatch.ILatch;
LSub1, LSub2: IMycSubscriber; // To hold the TLatchNotifierSubscriber instances
LInitStateP1, LInitStateP2: IMycLatch;
Subscriptions: array[1..2] of TSubscription; // To manage subscriptions
LInitStateP1, LInitStateP2: TLatch.ILatch;
Subscriptions: array[1..2] of TSignal.TSubscription; // To manage subscriptions
const
CMainFutureResult = 'AllPrerequisitesCompleted';
begin
@@ -335,8 +335,8 @@ end;
procedure TTestMycGateFuncFuture.Test_FanOut_MultipleFuturesWaitForOneTrigger;
var
LTriggerLatch: IMycLatch;
LFutureA, LFutureB: IMycFuture<Integer>;
LTriggerLatch: TLatch.ILatch;
LFutureA, LFutureB: TFuture<Integer>.IFuture;
LFlagFutureARan, LFlagFutureBRan: Boolean;
begin
LFlagFutureARan := False;
+9 -9
View File
@@ -120,10 +120,10 @@ end;
procedure TTestFuture.TestConstructWithPresetGate;
var
fut: TFuture<Integer>;
presetGate: IMycState;
presetGate: TState.IState;
resultValue: Integer;
begin
presetGate := TState.Null; // State.Null is an IMycState that is always set [cite: 68]
presetGate := TState.Null; // State.Null is an TState.IState that is always set [cite: 68]
Assert.IsTrue(presetGate.IsSet, 'The preset gate (State.Null) should be initially set.'); // Static string [cite: 55]
// Construct a future with a gate that is already set
@@ -148,17 +148,17 @@ end;
procedure TTestFuture.TestConstructWithDelayedGate;
var
fut: TFuture<Integer>;
delayedGate: IMycLatch; // IMycLatch implements IMycState [cite: 58]
delayedGate: TLatch.ILatch; // TLatch.ILatch implements TState.IState [cite: 58]
resultValue: Integer;
begin
delayedGate := TLatch.CreateLatch(1); // Create a latch that requires one notification to be set [cite: 66]
Assert.IsNotNull(delayedGate, 'The delayed gate (IMycLatch) should not be nil.'); // Static string
Assert.IsNotNull(delayedGate, 'The delayed gate (TLatch.ILatch) should not be nil.'); // Static string
Assert.IsFalse(delayedGate.State.IsSet, 'The delayed gate should not be initially set.'); // Static string [cite: 59, 55]
// Construct a future with a gate that is not yet set
fut :=
TFuture<Integer>.Construct(
delayedGate.State, // Get the IMycState interface from the latch [cite: 147, 59]
delayedGate.State, // Get the TState.IState interface from the latch [cite: 147, 59]
function: Integer begin Result := 45; end
);
@@ -220,7 +220,7 @@ procedure TTestFuture.TestChainWithGate;
var
fut1: TFuture<Integer>;
fut2: TFuture<string>;
delayedGate: IMycLatch;
delayedGate: TLatch.ILatch;
resultValue: string;
begin
delayedGate := TLatch.CreateLatch(1); // [cite: 66]
@@ -341,7 +341,7 @@ const
var
Futures: TArray<TFuture<Integer>>;
doneStates: TArray<TState>;
combinedStateAll: IMycState;
combinedStateAll: TState.IState;
masterFuture: TFuture<Boolean>;
i: Integer;
begin
@@ -374,7 +374,7 @@ begin
end;
combinedStateAll := TState.All(doneStates); // [cite: 67]
Assert.IsNotNull(combinedStateAll, 'State.All should return a valid IMycState.'); // Static string
Assert.IsNotNull(combinedStateAll, 'State.All should return a valid TState.IState.'); // Static string
// Create a master future that waits on the combined State.All state
masterFuture :=
@@ -447,7 +447,7 @@ begin
end;
combinedStateAny := TState.Any(doneStates); // [cite: 68]
Assert.IsNotNull(combinedStateAny, 'State.Any should return a valid IMycState.'); // Static string
Assert.IsNotNull(combinedStateAny, 'State.Any should return a valid TState.IState.'); // Static string
// Create a master future that waits on the combined State.Any state
masterFuture :=
+8 -8
View File
@@ -70,7 +70,7 @@ end;
procedure TMycTaskFactoryTests.TestCreateThreadExecutesAndSignals;
var
executed: Boolean;
threadState: IMycState;
threadState: TState.IState;
procWrapper: TProc;
begin
executed := False;
@@ -86,7 +86,7 @@ end;
procedure TMycTaskFactoryTests.TestRunImmediateJob;
var
jobExecuted: Boolean;
jobCompletedLatch: IMycLatch;
jobCompletedLatch: TLatch.ILatch;
begin
jobExecuted := False;
jobCompletedLatch := TLatch.CreateLatch(1); // Changed from Signals.CreateLatch
@@ -107,7 +107,7 @@ end;
procedure TMycTaskFactoryTests.TestRunDelayedJobExecutesAfterAllNotifies;
var
jobExecuted: Boolean;
jobCompletedLatch: IMycLatch;
jobCompletedLatch: TLatch.ILatch;
subscriber: IMycSubscriber;
begin
jobExecuted := False;
@@ -134,7 +134,7 @@ end;
procedure TMycTaskFactoryTests.TestWaitForAlreadySetState;
var
alreadySetLatch: IMycLatch;
alreadySetLatch: TLatch.ILatch;
startTime, endTime: Cardinal;
begin
// TMycLatch.CreateLatch(0) will return TMycLatch.Null
@@ -152,7 +152,7 @@ procedure TMycTaskFactoryTests.TestThreadInfoMethods;
var
inMainThreadInJob: Boolean;
inWorkerThreadInJob: Boolean;
jobDoneLatch: IMycLatch;
jobDoneLatch: TLatch.ILatch;
begin
inMainThreadInJob := True;
inWorkerThreadInJob := False;
@@ -178,7 +178,7 @@ end;
procedure TMycTaskFactoryTests.TestExceptionPropagationFromJob;
var
jobDoneLatch: IMycLatch;
jobDoneLatch: TLatch.ILatch;
begin
jobDoneLatch := TLatch.CreateLatch(1);
@@ -222,8 +222,8 @@ end;
procedure TMycTaskFactoryTests.TestWaitForInWorkerThreadRaisesException;
var
exceptionCaughtInJob: Boolean;
jobDoneLatch: IMycLatch;
dummyStateToWaitFor: IMycState;
jobDoneLatch: TLatch.ILatch;
dummyStateToWaitFor: TState.IState;
begin
exceptionCaughtInJob := False;
jobDoneLatch := TLatch.CreateLatch(1);