Refactoring

This commit is contained in:
Michael Schimmel
2025-06-02 12:27:52 +02:00
parent 86e2729a52
commit 762e7f83e2
8 changed files with 294 additions and 182 deletions
+15 -17
View File
@@ -8,7 +8,7 @@ uses
System.SyncObjs,
Myc.Signals, // For IMycLatch, TMycLatch, IMycState, IMycSubscriber [cite: 62, 68, 53, 45]
Myc.Core.Tasks, // For IMycTaskFactory, TMycTaskFactory [cite: 97, 113]
Myc.Futures; // For IMycFuture, TMycInitStateFuncFuture
Myc.Futures, Myc.Core.Futures; // For IMycFuture, TMycInitStateFuncFuture
type
// Helper class to notify a latch when its Notify method is called.
@@ -207,12 +207,8 @@ procedure TTestMycInitStateFuncFuture.Test_GetResult_BeforeDone_RaisesException;
var
LFuture: IMycFuture<Integer>;
LInitLatch: IMycLatch;
LExpectedExceptionRaised: Boolean;
const
CExpectedExceptionMessage = 'Result is not yet available for the future.';
begin
LExpectedExceptionRaised := False;
LInitLatch := TMycLatch.CreateLatch(1); // Create a latch that is not yet set [cite: 77, 212, 330]
LInitLatch := TMycLatch.CreateLatch(1);
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitLatch.State,
function: Integer
@@ -223,19 +219,21 @@ begin
Assert.IsFalse(LFuture.Done.IsSet, 'Future should not be marked as done initially.');
try
LFuture.GetResult;
except
on E: Exception do
Assert.WillRaise(
procedure
begin
Assert.AreEqual(CExpectedExceptionMessage, E.Message, 'Exception message mismatch.');
LExpectedExceptionRaised := True;
end;
end;
Assert.IsTrue(LExpectedExceptionRaised, 'Calling GetResult before done should raise an exception.');
LFuture.GetResult;
end );
LInitLatch.Notify; // [cite: 80, 215, 333]
FTaskFactory.WaitFor(LFuture.Done); //
LInitLatch.Notify;
FTaskFactory.WaitFor(LFuture.Done);
Assert.WillNotRaise(
procedure
begin
LFuture.GetResult;
end );
end;
procedure TTestMycInitStateFuncFuture.Test_FanIn_OneFutureWaitsForMultipleOthers;