Implemented TLazy + Tests
This commit is contained in:
+25
-10
@@ -7,15 +7,19 @@ uses
|
|||||||
Myc.Signals, Myc.TaskManager, Myc.Futures;
|
Myc.Signals, Myc.TaskManager, Myc.Futures;
|
||||||
|
|
||||||
type
|
type
|
||||||
// Abstract base class for IMycFuture<T> implementations.
|
|
||||||
TMycFuture<T> = class abstract( TInterfacedObject, IMycFuture<T> )
|
TMycFuture<T> = class abstract( TInterfacedObject, IMycFuture<T> )
|
||||||
protected
|
protected
|
||||||
function GetResult: T; virtual; abstract;
|
function GetResult: T; virtual; abstract;
|
||||||
function GetDone: IMycState; virtual; abstract;
|
function GetDone: IMycState; virtual; abstract;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Concrete future implementation triggered by an initial state, executing a TFunc<T>.
|
TMycNullFuture<T> = class( TMycFuture<T> )
|
||||||
TMycInitStateFuncFuture<T> = class( TMycFuture<T> )
|
protected
|
||||||
|
function GetResult: T; override;
|
||||||
|
function GetDone: IMycState; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TMycGateFuncFuture<T> = class(TMycFuture<T>)
|
||||||
private
|
private
|
||||||
FInit: TMycSubscription;
|
FInit: TMycSubscription;
|
||||||
FDone: IMycLatch;
|
FDone: IMycLatch;
|
||||||
@@ -24,20 +28,31 @@ type
|
|||||||
function GetResult: T; override;
|
function GetResult: T; override;
|
||||||
function GetDone: IMycState; override;
|
function GetDone: IMycState; override;
|
||||||
public
|
public
|
||||||
// Creates a future that executes AProc after AGate is set, using ATaskFactory.
|
|
||||||
constructor Create( const ATaskManager: IMycTaskManager; const AGate: IMycState; AProc: TFunc<T> );
|
constructor Create( const ATaskManager: IMycTaskManager; const AGate: IMycState; AProc: TFunc<T> );
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{ TMycInitStateFuncFuture<T> }
|
{ TMycNullFuture<T> }
|
||||||
|
|
||||||
constructor TMycInitStateFuncFuture<T>.Create( const ATaskManager: IMycTaskManager; const AGate: IMycState; AProc: TFunc<T> );
|
function TMycNullFuture<T>.GetDone: IMycState;
|
||||||
|
begin
|
||||||
|
Result := TState.Null;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMycNullFuture<T>.GetResult: T;
|
||||||
|
begin
|
||||||
|
Result := Default(T);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TMycGateFuncFuture<T> }
|
||||||
|
|
||||||
|
constructor TMycGateFuncFuture<T>.Create(const ATaskManager: IMycTaskManager; const AGate: IMycState; AProc: TFunc<T>);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
FDone := TState.CreateLatch( 1 );
|
FDone := TLatch.Construct( 1 );
|
||||||
|
|
||||||
// Subscribe the job execution to AGate.
|
// Subscribe the job execution to AGate.
|
||||||
// The job will run when AGate notifies the subscriber returned by Run.
|
// The job will run when AGate notifies the subscriber returned by Run.
|
||||||
@@ -58,7 +73,7 @@ begin
|
|||||||
end );
|
end );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TMycInitStateFuncFuture<T>.Destroy;
|
destructor TMycGateFuncFuture<T>.Destroy;
|
||||||
begin
|
begin
|
||||||
Assert( FDone.State.IsSet );
|
Assert( FDone.State.IsSet );
|
||||||
|
|
||||||
@@ -66,12 +81,12 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMycInitStateFuncFuture<T>.GetDone: IMycState;
|
function TMycGateFuncFuture<T>.GetDone: IMycState;
|
||||||
begin
|
begin
|
||||||
Result := FDone.State;
|
Result := FDone.State;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMycInitStateFuncFuture<T>.GetResult: T;
|
function TMycGateFuncFuture<T>.GetResult: T;
|
||||||
begin
|
begin
|
||||||
Assert( FDone.State.IsSet, 'Result is not yet available.' );
|
Assert( FDone.State.IsSet, 'Result is not yet available.' );
|
||||||
Result := FResult;
|
Result := FResult;
|
||||||
|
|||||||
+41
-36
@@ -9,18 +9,12 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
TMycState = class abstract( TInterfacedObject, IMycState )
|
TMycState = class abstract( TInterfacedObject, IMycState )
|
||||||
strict private
|
|
||||||
class var
|
|
||||||
FNull: IMycState;
|
|
||||||
class constructor ClassCreate;
|
|
||||||
protected
|
protected
|
||||||
function GetIsSet: Boolean; virtual; abstract;
|
function GetIsSet: Boolean; virtual; abstract;
|
||||||
public
|
public
|
||||||
function Subscribe(Subscriber: IMycSubscriber): TMycSubscription; virtual; abstract;
|
function Subscribe(Subscriber: IMycSubscriber): TMycSubscription; virtual; abstract;
|
||||||
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag); virtual; abstract;
|
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag); virtual; abstract;
|
||||||
property IsSet: Boolean read GetIsSet;
|
property IsSet: Boolean read GetIsSet;
|
||||||
// Provides access to the singleton null latch instance (always set).
|
|
||||||
class property Null: IMycState read FNull;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// TMycNullState implements a "null object" pattern for IMycState.
|
// TMycNullState implements a "null object" pattern for IMycState.
|
||||||
@@ -42,9 +36,6 @@ type
|
|||||||
TMycLatch = class(TMycState, IMycLatch)
|
TMycLatch = class(TMycState, IMycLatch)
|
||||||
strict private
|
strict private
|
||||||
FSubscribers: TMycNotifyList<IMycSubscriber>; // List of subscribers waiting for this latch to be set.
|
FSubscribers: TMycNotifyList<IMycSubscriber>; // List of subscribers waiting for this latch to be set.
|
||||||
class var
|
|
||||||
FNull: IMycLatch; // Singleton instance of a latch that is always set.
|
|
||||||
class constructor ClassCreate; // Class constructor to initialize FNull.
|
|
||||||
private
|
private
|
||||||
[volatile] FCount: Integer; // The internal countdown value for the latch.
|
[volatile] FCount: Integer; // The internal countdown value for the latch.
|
||||||
function GetState: IMycState; // Implementation for IMycLatch.GetState and IMycFlag.GetState.
|
function GetState: IMycState; // Implementation for IMycLatch.GetState and IMycFlag.GetState.
|
||||||
@@ -56,9 +47,6 @@ type
|
|||||||
constructor Create(ACount: Integer);
|
constructor Create(ACount: Integer);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
// Factory method: creates a new countdown latch or returns the Null latch if Count <= 0.
|
|
||||||
class function CreateLatch(Count: Integer): IMycLatch; static;
|
|
||||||
|
|
||||||
// IMycSignal implementation
|
// IMycSignal implementation
|
||||||
function Subscribe(Subscriber: IMycSubscriber): TMycSubscription; override;
|
function Subscribe(Subscriber: IMycSubscriber): TMycSubscription; override;
|
||||||
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag); override;
|
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag); override;
|
||||||
@@ -67,9 +55,12 @@ type
|
|||||||
// Decrements the internal count. If the count reaches zero,
|
// Decrements the internal count. If the count reaches zero,
|
||||||
// registered subscribers are notified, and the latch becomes permanently set.
|
// registered subscribers are notified, and the latch becomes permanently set.
|
||||||
function Notify: Boolean;
|
function Notify: Boolean;
|
||||||
|
end;
|
||||||
|
|
||||||
// Provides access to the singleton null latch instance (always set).
|
TMycNullLatch = class( TInterfacedObject, IMycLatch )
|
||||||
class property Null: IMycLatch read FNull;
|
private
|
||||||
|
function GetState: IMycState;
|
||||||
|
function Notify: Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// TMycDirty implements a resettable "dirty flag".
|
// TMycDirty implements a resettable "dirty flag".
|
||||||
@@ -91,7 +82,6 @@ type
|
|||||||
// Factory method to create a new TMycDirty instance.
|
// Factory method to create a new TMycDirty instance.
|
||||||
class function CreateDirty: IMycDirty; static;
|
class function CreateDirty: IMycDirty; static;
|
||||||
|
|
||||||
// IMycSignal implementation
|
|
||||||
function Subscribe(Subscriber: IMycSubscriber): TMycSubscription; override;
|
function Subscribe(Subscriber: IMycSubscriber): TMycSubscription; override;
|
||||||
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag); override;
|
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag); override;
|
||||||
|
|
||||||
@@ -103,17 +93,18 @@ type
|
|||||||
function Reset: Boolean;
|
function Reset: Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TMycNullDirty = class( TInterfacedObject, IMycDirty )
|
||||||
|
private
|
||||||
|
function GetState: IMycState;
|
||||||
|
function Notify: Boolean;
|
||||||
|
function Reset: Boolean;
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
System.SyncObjs; // For TInterlocked
|
System.SyncObjs; // For TInterlocked
|
||||||
|
|
||||||
class constructor TMycState.ClassCreate;
|
|
||||||
begin
|
|
||||||
// Create a singleton null latch instance that is initially (and always) set.
|
|
||||||
FNull := TMycNullState.Create(); // Calls the instance constructor
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TMycNullState }
|
{ TMycNullState }
|
||||||
|
|
||||||
constructor TMycNullState.Create;
|
constructor TMycNullState.Create;
|
||||||
@@ -142,6 +133,18 @@ begin
|
|||||||
// Unsubscribing from a null state has no effect.
|
// Unsubscribing from a null state has no effect.
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TMycNullLatch }
|
||||||
|
|
||||||
|
function TMycNullLatch.GetState: IMycState;
|
||||||
|
begin
|
||||||
|
Result := TState.Null;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMycNullLatch.Notify: Boolean;
|
||||||
|
begin
|
||||||
|
Result := false;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TMycLatch }
|
{ TMycLatch }
|
||||||
|
|
||||||
constructor TMycLatch.Create(ACount: Integer);
|
constructor TMycLatch.Create(ACount: Integer);
|
||||||
@@ -152,27 +155,12 @@ begin
|
|||||||
FSubscribers.Create;
|
FSubscribers.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class constructor TMycLatch.ClassCreate;
|
|
||||||
begin
|
|
||||||
// Create a singleton null latch instance that is initially (and always) set.
|
|
||||||
FNull := TMycLatch.Create(0); // Calls the instance constructor
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TMycLatch.Destroy;
|
destructor TMycLatch.Destroy;
|
||||||
begin
|
begin
|
||||||
FSubscribers.Destroy;
|
FSubscribers.Destroy;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TMycLatch.CreateLatch(Count: Integer): IMycLatch;
|
|
||||||
begin
|
|
||||||
// Factory method: returns a new latch or the shared Null latch if Count <= 0.
|
|
||||||
if Count > 0 then
|
|
||||||
Result := TMycLatch.Create(Count) // Instance constructor
|
|
||||||
else
|
|
||||||
Result := FNull;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMycLatch.Notify: Boolean;
|
function TMycLatch.Notify: Boolean;
|
||||||
var
|
var
|
||||||
currentCountAfterDecrement: Integer;
|
currentCountAfterDecrement: Integer;
|
||||||
@@ -259,6 +247,23 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TMycNullDirty }
|
||||||
|
|
||||||
|
function TMycNullDirty.GetState: IMycState;
|
||||||
|
begin
|
||||||
|
Result := TState.Null;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMycNullDirty.Notify: Boolean;
|
||||||
|
begin
|
||||||
|
Result := false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMycNullDirty.Reset: Boolean;
|
||||||
|
begin
|
||||||
|
Result := true;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TMycDirty }
|
{ TMycDirty }
|
||||||
|
|
||||||
constructor TMycDirty.Create;
|
constructor TMycDirty.Create;
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ begin
|
|||||||
FWorkThreads[i].Free;
|
FWorkThreads[i].Free;
|
||||||
|
|
||||||
if Assigned(FException) then
|
if Assigned(FException) then
|
||||||
FException.Free;
|
FException.Free;
|
||||||
|
|
||||||
FWorkGate.Free;
|
FWorkGate.Free;
|
||||||
FWorkStack.Clear;
|
FWorkStack.Clear;
|
||||||
@@ -203,7 +203,7 @@ var
|
|||||||
capturedProc: TProc;
|
capturedProc: TProc;
|
||||||
begin
|
begin
|
||||||
// Create a latch that will be signaled when the proc finishes
|
// Create a latch that will be signaled when the proc finishes
|
||||||
res := TMycLatch.CreateLatch(1); // Changed to use direct static call on TMycLatch
|
res := TLatch.Construct(1); // Changed to use direct static call on TMycLatch
|
||||||
|
|
||||||
capturedProc := Proc; // Capture Proc for the anonymous method
|
capturedProc := Proc; // Capture Proc for the anonymous method
|
||||||
CreateAnonymousThread('Thread',
|
CreateAnonymousThread('Thread',
|
||||||
@@ -303,7 +303,7 @@ begin
|
|||||||
raise ETaskException.Create('Task factory terminated');
|
raise ETaskException.Create('Task factory terminated');
|
||||||
|
|
||||||
if not Assigned(Job) then
|
if not Assigned(Job) then
|
||||||
exit(TMycLatch.Null); // Already correct, uses direct static property on TMycLatch
|
exit(TLatch.Null); // Already correct, uses direct static property on TMycLatch
|
||||||
|
|
||||||
// Create a pending job
|
// Create a pending job
|
||||||
Result := TMycPendingJob.Create(Self, Job);
|
Result := TMycPendingJob.Create(Self, Job);
|
||||||
|
|||||||
+10
-3
@@ -20,16 +20,20 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
TFuture<T> = record
|
TFuture<T> = record
|
||||||
strict private
|
private
|
||||||
FFuture: IMycFuture<T>;
|
FFuture: IMycFuture<T>;
|
||||||
function GetDone: IMycState; inline;
|
function GetDone: IMycState; inline;
|
||||||
function GetResult: T; inline;
|
function GetResult: T; inline;
|
||||||
|
|
||||||
|
class var
|
||||||
|
FNull: IMycFuture<T>;
|
||||||
|
|
||||||
class constructor CreateClass;
|
class constructor CreateClass;
|
||||||
class destructor DestroyClass;
|
class destructor DestroyClass;
|
||||||
|
|
||||||
public
|
public
|
||||||
constructor Create(const AFuture: IMycFuture<T>);
|
constructor Create(const AFuture: IMycFuture<T>);
|
||||||
|
|
||||||
class operator Implicit(const A: IMycFuture<T>): TFuture<T>; overload;
|
class operator Implicit(const A: IMycFuture<T>): TFuture<T>; overload;
|
||||||
class operator Implicit(const A: TFuture<T>): IMycFuture<T>; overload;
|
class operator Implicit(const A: TFuture<T>): IMycFuture<T>; overload;
|
||||||
|
|
||||||
@@ -52,11 +56,14 @@ uses
|
|||||||
constructor TFuture<T>.Create(const AFuture: IMycFuture<T>);
|
constructor TFuture<T>.Create(const AFuture: IMycFuture<T>);
|
||||||
begin
|
begin
|
||||||
FFuture := AFuture;
|
FFuture := AFuture;
|
||||||
|
if not Assigned(FFuture) then
|
||||||
|
FFuture := FNull;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class constructor TFuture<T>.CreateClass;
|
class constructor TFuture<T>.CreateClass;
|
||||||
begin
|
begin
|
||||||
TMycTaskFactory.AquireTaskManager;
|
TMycTaskFactory.AquireTaskManager;
|
||||||
|
FNull := TMycNullFuture<T>.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class destructor TFuture<T>.DestroyClass;
|
class destructor TFuture<T>.DestroyClass;
|
||||||
@@ -77,12 +84,12 @@ end;
|
|||||||
|
|
||||||
class function TFuture<T>.Construct(const Proc: TFunc<T>): IMycFuture<T>;
|
class function TFuture<T>.Construct(const Proc: TFunc<T>): IMycFuture<T>;
|
||||||
begin
|
begin
|
||||||
Result := TMycInitStateFuncFuture<T>.Create( TaskManager, nil, Proc );
|
Result := TMycGateFuncFuture<T>.Create( TaskManager, nil, Proc );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TFuture<T>.Construct(const Gate: IMycState; const Proc: TFunc<T>): IMycFuture<T>;
|
class function TFuture<T>.Construct(const Gate: IMycState; const Proc: TFunc<T>): IMycFuture<T>;
|
||||||
begin
|
begin
|
||||||
Result := TMycInitStateFuncFuture<T>.Create( TaskManager, Gate, Proc );
|
Result := TMycGateFuncFuture<T>.Create( TaskManager, Gate, Proc );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFuture<T>.GetDone: IMycState;
|
function TFuture<T>.GetDone: IMycState;
|
||||||
|
|||||||
+87
-24
@@ -24,7 +24,7 @@ type
|
|||||||
// Unsubscribes from the associated TState.
|
// Unsubscribes from the associated TState.
|
||||||
procedure Unsubscribe;
|
procedure Unsubscribe;
|
||||||
class operator Initialize( out Dest: TMycSubscription );
|
class operator Initialize( out Dest: TMycSubscription );
|
||||||
property TState: IMycState read GetState;
|
property State: IMycState read GetState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IMycState = interface
|
IMycState = interface
|
||||||
@@ -39,6 +39,30 @@ type
|
|||||||
property IsSet: Boolean read GetIsSet;
|
property IsSet: Boolean read GetIsSet;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TState = record // helper for IMycState
|
||||||
|
strict private
|
||||||
|
class var
|
||||||
|
FNull: IMycState;
|
||||||
|
class constructor ClassCreate;
|
||||||
|
private
|
||||||
|
FState: IMycState;
|
||||||
|
function GetIsSet: Boolean; inline;
|
||||||
|
public
|
||||||
|
constructor Create(const AState: IMycState);
|
||||||
|
class operator Implicit(const A: IMycState): TState; overload;
|
||||||
|
class operator Implicit(const A: TState): IMycState; overload;
|
||||||
|
|
||||||
|
class function All( const States: TArray<IMycState> ): IMycState; static;
|
||||||
|
class function Any( const States: TArray<IMycState> ): IMycState; static;
|
||||||
|
|
||||||
|
class property Null: IMycState read FNull;
|
||||||
|
|
||||||
|
function Subscribe(Subscriber: IMycSubscriber): TMycSubscription; inline;
|
||||||
|
procedure Unsubscribe(Tag: Pointer); inline;
|
||||||
|
|
||||||
|
property IsSet: Boolean read GetIsSet;
|
||||||
|
end;
|
||||||
|
|
||||||
// IMycLatch is a specific type of flag that, once set, remains set (non-resettable).
|
// IMycLatch is a specific type of flag that, once set, remains set (non-resettable).
|
||||||
// It typically becomes set when an internal countdown reaches zero.
|
// It typically becomes set when an internal countdown reaches zero.
|
||||||
IMycLatch = interface( IMycSubscriber )
|
IMycLatch = interface( IMycSubscriber )
|
||||||
@@ -48,6 +72,16 @@ type
|
|||||||
// Inherits IMycSubscriber and State property from IMycFlag. No new members.
|
// Inherits IMycSubscriber and State property from IMycFlag. No new members.
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TLatch = record
|
||||||
|
strict private
|
||||||
|
class var
|
||||||
|
FNull: IMycLatch;
|
||||||
|
class constructor ClassCreate;
|
||||||
|
public
|
||||||
|
class function Construct(Count: Integer): IMycLatch; static;
|
||||||
|
class property Null: IMycLatch read FNull;
|
||||||
|
end;
|
||||||
|
|
||||||
// IMycDirty represents a resettable flag, typically indicating if a State is "dirty" (requiring attention) or "clean".
|
// IMycDirty represents a resettable flag, typically indicating if a State is "dirty" (requiring attention) or "clean".
|
||||||
// It inherits from IMycFlag, meaning it has a State, can be notified, and subscribed to.
|
// It inherits from IMycFlag, meaning it has a State, can be notified, and subscribed to.
|
||||||
IMycDirty = interface( IMycSubscriber )
|
IMycDirty = interface( IMycSubscriber )
|
||||||
@@ -59,19 +93,14 @@ type
|
|||||||
property State: IMycState read GetState;
|
property State: IMycState read GetState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TState = record
|
TDirty = record
|
||||||
private
|
strict private
|
||||||
FState: IMycState;
|
class var
|
||||||
class function GetNull: IMycState; static;
|
FNull: IMycDirty;
|
||||||
|
class constructor ClassCreate;
|
||||||
public
|
public
|
||||||
constructor Create(const AState: IMycState);
|
class function Construct: IMycDirty; static;
|
||||||
class function CreateLatch( Count: Integer ): IMycLatch; static;
|
class property Null: IMycDirty read FNull;
|
||||||
class function CreateDirty: IMycDirty; static;
|
|
||||||
class function All( const States: TArray<IMycState> ): IMycState; static;
|
|
||||||
class function Any( const States: TArray<IMycState> ): IMycState; static;
|
|
||||||
class operator Implicit(const A: IMycState): TState; overload;
|
|
||||||
class operator Implicit(const A: TState): IMycState; overload;
|
|
||||||
class property Null: IMycState read GetNull;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@@ -92,7 +121,7 @@ end;
|
|||||||
procedure TMycSubscription.Unsubscribe;
|
procedure TMycSubscription.Unsubscribe;
|
||||||
begin
|
begin
|
||||||
FState.Unsubscribe( FTag );
|
FState.Unsubscribe( FTag );
|
||||||
FState := TMycState.Null;
|
FState := TState.Null;
|
||||||
FTag := nil;
|
FTag := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -103,7 +132,7 @@ end;
|
|||||||
|
|
||||||
class operator TMycSubscription.Initialize( out Dest: TMycSubscription );
|
class operator TMycSubscription.Initialize( out Dest: TMycSubscription );
|
||||||
begin
|
begin
|
||||||
Dest.FState := TMycState.Null;
|
Dest.FState := TState.Null;
|
||||||
Dest.FTag := nil;
|
Dest.FTag := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -113,19 +142,20 @@ constructor TState.Create(const AState: IMycState);
|
|||||||
begin
|
begin
|
||||||
FState := AState;
|
FState := AState;
|
||||||
if not Assigned(FState) then
|
if not Assigned(FState) then
|
||||||
FState := TMycState.Null;
|
FState := FNull;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TState.CreateLatch( Count: Integer ): IMycLatch;
|
class constructor TState.ClassCreate;
|
||||||
begin
|
begin
|
||||||
Result := TMycLatch.CreateLatch( Count );
|
// Create a singleton null latch instance that is initially (and always) set.
|
||||||
|
FNull := TMycNullState.Create(); // Calls the instance constructor
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TState.All( const States: TArray<IMycState> ): IMycState;
|
class function TState.All( const States: TArray<IMycState> ): IMycState;
|
||||||
var
|
var
|
||||||
Latch: IMycLatch;
|
Latch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
Latch := CreateLatch( Length( States ) );
|
Latch := TLatch.Construct( Length( States ) );
|
||||||
for var i := 0 to High( States ) do
|
for var i := 0 to High( States ) do
|
||||||
States[i].Subscribe( Latch );
|
States[i].Subscribe( Latch );
|
||||||
Result := Latch.State;
|
Result := Latch.State;
|
||||||
@@ -141,21 +171,26 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
Latch := CreateLatch( 1 );
|
Latch := TLatch.Construct( 1 );
|
||||||
for var i := 0 to High( States ) do
|
for var i := 0 to High( States ) do
|
||||||
States[i].Subscribe( Latch );
|
States[i].Subscribe( Latch );
|
||||||
Result := Latch.State;
|
Result := Latch.State;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TState.CreateDirty: IMycDirty;
|
function TState.GetIsSet: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := TMycDirty.CreateDirty;
|
Result := FState.IsSet;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TState.GetNull: IMycState;
|
function TState.Subscribe(Subscriber: IMycSubscriber): TMycSubscription;
|
||||||
begin
|
begin
|
||||||
Result := TMycState.Null;
|
Result := FState.Subscribe(Subscriber);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TState.Unsubscribe(Tag: Pointer);
|
||||||
|
begin
|
||||||
|
FState.Unsubscribe(Tag);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class operator TState.Implicit(const A: TState): IMycState;
|
class operator TState.Implicit(const A: TState): IMycState;
|
||||||
@@ -168,4 +203,32 @@ begin
|
|||||||
Result.Create( A );
|
Result.Create( A );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TLatch }
|
||||||
|
|
||||||
|
class constructor TLatch.ClassCreate;
|
||||||
|
begin
|
||||||
|
// Create a singleton null latch instance that is initially (and always) set.
|
||||||
|
FNull := TMycNullLatch.Create; // Calls the instance constructor
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TLatch.Construct(Count: Integer): IMycLatch;
|
||||||
|
begin
|
||||||
|
if Count > 0 then
|
||||||
|
Result := TMycLatch.Create( Count )
|
||||||
|
else
|
||||||
|
Result := FNull;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TDirty }
|
||||||
|
|
||||||
|
class constructor TDirty.ClassCreate;
|
||||||
|
begin
|
||||||
|
FNull := TMycNullDirty.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TDirty.Construct: IMycDirty;
|
||||||
|
begin
|
||||||
|
Result := TMycDirty.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|||||||
+5
-1
@@ -28,7 +28,11 @@ uses
|
|||||||
Myc.TaskManager in '..\Src\Myc.TaskManager.pas',
|
Myc.TaskManager in '..\Src\Myc.TaskManager.pas',
|
||||||
Myc.Core.Futures in '..\Src\Myc.Core.Futures.pas',
|
Myc.Core.Futures in '..\Src\Myc.Core.Futures.pas',
|
||||||
Myc.Core.Signals in '..\Src\Myc.Core.Signals.pas',
|
Myc.Core.Signals in '..\Src\Myc.Core.Signals.pas',
|
||||||
TestFutures in 'TestFutures.pas';
|
TestFutures in 'TestFutures.pas',
|
||||||
|
Myc.Lazy in '..\Src\Myc.Lazy.pas',
|
||||||
|
Myc.Core.Lazy in '..\Src\Myc.Core.Lazy.pas',
|
||||||
|
Myc.Test.Core.Lazy in '..\Src\Myc.Test.Core.Lazy.pas',
|
||||||
|
Myc.Test.Lazy in '..\Src\Myc.Test.Lazy.pas';
|
||||||
|
|
||||||
{ keep comment here to protect the following conditional from being removed by the IDE when adding a unit }
|
{ keep comment here to protect the following conditional from being removed by the IDE when adding a unit }
|
||||||
{$IFNDEF TESTINSIGHT}
|
{$IFNDEF TESTINSIGHT}
|
||||||
|
|||||||
+14
-10
@@ -64,9 +64,9 @@
|
|||||||
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
|
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
|
||||||
<Debugger_RunParams>--exitbehavior:Pause</Debugger_RunParams>
|
<Debugger_RunParams>--exitbehavior:Pause</Debugger_RunParams>
|
||||||
<DCC_Define>TESTINSIGHT;$(DCC_Define)</DCC_Define>
|
<DCC_Define>TESTINSIGHT;$(DCC_Define)</DCC_Define>
|
||||||
<PostBuildEvent><![CDATA[T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src
|
|
||||||
$(PostBuildEvent)]]></PostBuildEvent>
|
|
||||||
<PostBuildEventExecuteWhen>TargetOutOfDate</PostBuildEventExecuteWhen>
|
<PostBuildEventExecuteWhen>TargetOutOfDate</PostBuildEventExecuteWhen>
|
||||||
|
<PreBuildEvent><![CDATA[T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src
|
||||||
|
$(PreBuildEvent)]]></PreBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Base_Win32)'!=''">
|
<PropertyGroup Condition="'$(Base_Win32)'!=''">
|
||||||
<DCC_UsePackage>vclwinx;fmx;vclie;DbxCommonDriver;bindengine;IndyIPCommon;VCLRESTComponents;FireDACCommonODBC;FireDACCommonDriver;IndyProtocols;vclx;Skia.Package.RTL;IndyIPClient;dbxcds;vcledge;bindcompvclwinx;FmxTeeUI;bindcompfmx;inetdb;FireDACSqliteDriver;DbxClientDriver;Tee;soapmidas;vclactnband;TeeUI;fmxFireDAC;dbexpress;DBXMySQLDriver;VclSmp;inet;vcltouch;fmxase;dbrtl;Skia.Package.FMX;fmxdae;TeeDB;FireDACMSAccDriver;CustomIPTransport;vcldsnap;DBXInterBaseDriver;IndySystem;Skia.Package.VCL;vcldb;vclFireDAC;bindcomp;FireDACCommon;inetstn;IndyCore;RESTBackendComponents;bindcompdbx;rtl;FireDACMySQLDriver;FireDACADSDriver;RESTComponents;DBXSqliteDriver;vcl;IndyIPServer;dsnapxml;dsnapcon;adortl;vclimg;FireDACPgDriver;FireDAC;inetdbxpress;xmlrtl;tethering;bindcompvcl;dsnap;CloudService;fmxobj;bindcompvclsmp;FMXTee;soaprtl;soapserver;FireDACIBDriver;$(DCC_UsePackage)</DCC_UsePackage>
|
<DCC_UsePackage>vclwinx;fmx;vclie;DbxCommonDriver;bindengine;IndyIPCommon;VCLRESTComponents;FireDACCommonODBC;FireDACCommonDriver;IndyProtocols;vclx;Skia.Package.RTL;IndyIPClient;dbxcds;vcledge;bindcompvclwinx;FmxTeeUI;bindcompfmx;inetdb;FireDACSqliteDriver;DbxClientDriver;Tee;soapmidas;vclactnband;TeeUI;fmxFireDAC;dbexpress;DBXMySQLDriver;VclSmp;inet;vcltouch;fmxase;dbrtl;Skia.Package.FMX;fmxdae;TeeDB;FireDACMSAccDriver;CustomIPTransport;vcldsnap;DBXInterBaseDriver;IndySystem;Skia.Package.VCL;vcldb;vclFireDAC;bindcomp;FireDACCommon;inetstn;IndyCore;RESTBackendComponents;bindcompdbx;rtl;FireDACMySQLDriver;FireDACADSDriver;RESTComponents;DBXSqliteDriver;vcl;IndyIPServer;dsnapxml;dsnapcon;adortl;vclimg;FireDACPgDriver;FireDAC;inetdbxpress;xmlrtl;tethering;bindcompvcl;dsnap;CloudService;fmxobj;bindcompvclsmp;FMXTee;soaprtl;soapserver;FireDACIBDriver;$(DCC_UsePackage)</DCC_UsePackage>
|
||||||
@@ -128,6 +128,10 @@ $(PostBuildEvent)]]></PostBuildEvent>
|
|||||||
<DCCReference Include="..\Src\Myc.Core.Futures.pas"/>
|
<DCCReference Include="..\Src\Myc.Core.Futures.pas"/>
|
||||||
<DCCReference Include="..\Src\Myc.Core.Signals.pas"/>
|
<DCCReference Include="..\Src\Myc.Core.Signals.pas"/>
|
||||||
<DCCReference Include="TestFutures.pas"/>
|
<DCCReference Include="TestFutures.pas"/>
|
||||||
|
<DCCReference Include="..\Src\Myc.Lazy.pas"/>
|
||||||
|
<DCCReference Include="..\Src\Myc.Core.Lazy.pas"/>
|
||||||
|
<DCCReference Include="..\Src\Myc.Test.Core.Lazy.pas"/>
|
||||||
|
<DCCReference Include="..\Src\Myc.Test.Lazy.pas"/>
|
||||||
<BuildConfiguration Include="Base">
|
<BuildConfiguration Include="Base">
|
||||||
<Key>Base</Key>
|
<Key>Base</Key>
|
||||||
</BuildConfiguration>
|
</BuildConfiguration>
|
||||||
@@ -1149,35 +1153,35 @@ $(PostBuildEvent)]]></PostBuildEvent>
|
|||||||
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
|
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
|
||||||
<Import Project="$(MSBuildProjectName).deployproj" Condition="Exists('$(MSBuildProjectName).deployproj')"/>
|
<Import Project="$(MSBuildProjectName).deployproj" Condition="Exists('$(MSBuildProjectName).deployproj')"/>
|
||||||
<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='Win32'">
|
<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='Win32'">
|
||||||
<PreBuildEvent/>
|
<PreBuildEvent>T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src</PreBuildEvent>
|
||||||
<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
|
<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
|
||||||
<PreLinkEvent/>
|
<PreLinkEvent/>
|
||||||
<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
|
<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
|
||||||
<PostBuildEvent>T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src</PostBuildEvent>
|
<PostBuildEvent/>
|
||||||
<PostBuildEventIgnoreExitCode>False</PostBuildEventIgnoreExitCode>
|
<PostBuildEventIgnoreExitCode>False</PostBuildEventIgnoreExitCode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='Win64'">
|
<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='Win64'">
|
||||||
<PreBuildEvent/>
|
<PreBuildEvent>T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src</PreBuildEvent>
|
||||||
<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
|
<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
|
||||||
<PreLinkEvent/>
|
<PreLinkEvent/>
|
||||||
<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
|
<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
|
||||||
<PostBuildEvent>T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src</PostBuildEvent>
|
<PostBuildEvent/>
|
||||||
<PostBuildEventIgnoreExitCode>False</PostBuildEventIgnoreExitCode>
|
<PostBuildEventIgnoreExitCode>False</PostBuildEventIgnoreExitCode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='Win32'">
|
<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='Win32'">
|
||||||
<PreBuildEvent/>
|
<PreBuildEvent>T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src</PreBuildEvent>
|
||||||
<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
|
<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
|
||||||
<PreLinkEvent/>
|
<PreLinkEvent/>
|
||||||
<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
|
<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
|
||||||
<PostBuildEvent>T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src</PostBuildEvent>
|
<PostBuildEvent/>
|
||||||
<PostBuildEventIgnoreExitCode>False</PostBuildEventIgnoreExitCode>
|
<PostBuildEventIgnoreExitCode>False</PostBuildEventIgnoreExitCode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='Win64'">
|
<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='Win64'">
|
||||||
<PreBuildEvent/>
|
<PreBuildEvent>T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src</PreBuildEvent>
|
||||||
<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
|
<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
|
||||||
<PreLinkEvent/>
|
<PreLinkEvent/>
|
||||||
<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
|
<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
|
||||||
<PostBuildEvent>T:\DelphiIntfExtract\Win64\Debug\ExtractPascalInterfaces.exe -o T:\Myc\intf.txt T:\Myc\src</PostBuildEvent>
|
<PostBuildEvent/>
|
||||||
<PostBuildEventIgnoreExitCode>False</PostBuildEventIgnoreExitCode>
|
<PostBuildEventIgnoreExitCode>False</PostBuildEventIgnoreExitCode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
+26
-26
@@ -23,7 +23,7 @@ type
|
|||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
[IgnoreMemoryLeaks(true)]
|
[IgnoreMemoryLeaks(true)]
|
||||||
TTestMycInitStateFuncFuture = class(TObject)
|
TTestMycGateFuncFuture = class(TObject)
|
||||||
private
|
private
|
||||||
FTaskFactory: IMycTaskFactory;
|
FTaskFactory: IMycTaskFactory;
|
||||||
FProcExecutionCount: Integer; // Counter for side effects of AProc
|
FProcExecutionCount: Integer; // Counter for side effects of AProc
|
||||||
@@ -67,16 +67,16 @@ begin
|
|||||||
Result := False; // This subscriber is typically one-shot for this purpose.
|
Result := False; // This subscriber is typically one-shot for this purpose.
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TTestMycInitStateFuncFuture }
|
{ TTestMycGateFuncFuture }
|
||||||
|
|
||||||
procedure TTestMycInitStateFuncFuture.Setup;
|
procedure TTestMycGateFuncFuture.Setup;
|
||||||
begin
|
begin
|
||||||
FTaskFactory := TMycTaskFactory.Create; // Create a new task factory instance for each test [cite: 113, 235, 353]
|
FTaskFactory := TMycTaskFactory.Create; // Create a new task factory instance for each test [cite: 113, 235, 353]
|
||||||
FProcExecutionCount := 0;
|
FProcExecutionCount := 0;
|
||||||
FSharedCounter := 0;
|
FSharedCounter := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestMycInitStateFuncFuture.TearDown;
|
procedure TTestMycGateFuncFuture.TearDown;
|
||||||
begin
|
begin
|
||||||
if Assigned(FTaskFactory) then
|
if Assigned(FTaskFactory) then
|
||||||
begin
|
begin
|
||||||
@@ -85,7 +85,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestMycInitStateFuncFuture.Test_BasicSuccess_WithImmediateInitState;
|
procedure TTestMycGateFuncFuture.Test_BasicSuccess_WithImmediateInitState;
|
||||||
var
|
var
|
||||||
LFuture: IMycFuture<Integer>;
|
LFuture: IMycFuture<Integer>;
|
||||||
LInitStateAsState: IMycState; // Parameter for Create
|
LInitStateAsState: IMycState; // Parameter for Create
|
||||||
@@ -96,7 +96,7 @@ begin
|
|||||||
// Use TMycLatch.Null for an already set init state [cite: 71, 81, 206, 216, 324, 334]
|
// Use TMycLatch.Null for an already set init state [cite: 71, 81, 206, 216, 324, 334]
|
||||||
LInitStateAsState := TState.Null;
|
LInitStateAsState := TState.Null;
|
||||||
|
|
||||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateAsState,
|
LFuture := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LInitStateAsState,
|
||||||
function: Integer
|
function: Integer
|
||||||
begin
|
begin
|
||||||
Inc(Self.FProcExecutionCount);
|
Inc(Self.FProcExecutionCount);
|
||||||
@@ -112,7 +112,7 @@ begin
|
|||||||
Assert.AreEqual(CExpectedResult, LResultValue, 'GetResult returned an unexpected value.');
|
Assert.AreEqual(CExpectedResult, LResultValue, 'GetResult returned an unexpected value.');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestMycInitStateFuncFuture.Test_ChainedExecution_WithDelayedInitState;
|
procedure TTestMycGateFuncFuture.Test_ChainedExecution_WithDelayedInitState;
|
||||||
var
|
var
|
||||||
LFuture: IMycFuture<string>;
|
LFuture: IMycFuture<string>;
|
||||||
LInitLatch: IMycLatch;
|
LInitLatch: IMycLatch;
|
||||||
@@ -120,9 +120,9 @@ var
|
|||||||
const
|
const
|
||||||
CExpectedResult = 'ChainCompleted';
|
CExpectedResult = 'ChainCompleted';
|
||||||
begin
|
begin
|
||||||
LInitLatch := TState.CreateLatch(1); // Create an init state that is not yet set [cite: 77, 212, 330]
|
LInitLatch := TLatch.Construct(1); // Create an init state that is not yet set [cite: 77, 212, 330]
|
||||||
|
|
||||||
LFuture := TMycInitStateFuncFuture<string>.Create(FTaskFactory, LInitLatch.State,
|
LFuture := TMycGateFuncFuture<string>.Create(FTaskFactory, LInitLatch.State,
|
||||||
function: string
|
function: string
|
||||||
begin
|
begin
|
||||||
Inc(Self.FProcExecutionCount);
|
Inc(Self.FProcExecutionCount);
|
||||||
@@ -143,7 +143,7 @@ begin
|
|||||||
Assert.AreEqual(CExpectedResult, LResultValue, 'GetResult returned an unexpected value after delayed init.');
|
Assert.AreEqual(CExpectedResult, LResultValue, 'GetResult returned an unexpected value after delayed init.');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestMycInitStateFuncFuture.Test_ExceptionInProc_HandledAsPlanned;
|
procedure TTestMycGateFuncFuture.Test_ExceptionInProc_HandledAsPlanned;
|
||||||
var
|
var
|
||||||
LFuture: IMycFuture<Integer>;
|
LFuture: IMycFuture<Integer>;
|
||||||
LLocalTaskFactory: IMycTaskFactory;
|
LLocalTaskFactory: IMycTaskFactory;
|
||||||
@@ -157,7 +157,7 @@ begin
|
|||||||
LLocalTaskFactory := TMycTaskFactory.Create;
|
LLocalTaskFactory := TMycTaskFactory.Create;
|
||||||
LInitStateAsState := TState.Null; // Immediate execution
|
LInitStateAsState := TState.Null; // Immediate execution
|
||||||
|
|
||||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(LLocalTaskFactory, LInitStateAsState,
|
LFuture := TMycGateFuncFuture<Integer>.Create(LLocalTaskFactory, LInitStateAsState,
|
||||||
function: Integer
|
function: Integer
|
||||||
begin
|
begin
|
||||||
Inc(Self.FProcExecutionCount);
|
Inc(Self.FProcExecutionCount);
|
||||||
@@ -203,14 +203,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestMycInitStateFuncFuture.Test_GetResult_BeforeDone_RaisesException;
|
procedure TTestMycGateFuncFuture.Test_GetResult_BeforeDone_RaisesException;
|
||||||
var
|
var
|
||||||
LFuture: IMycFuture<Integer>;
|
LFuture: IMycFuture<Integer>;
|
||||||
LInitLatch: IMycLatch;
|
LInitLatch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
LInitLatch := TState.CreateLatch(1);
|
LInitLatch := TLatch.Construct(1);
|
||||||
|
|
||||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitLatch.State,
|
LFuture := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LInitLatch.State,
|
||||||
function: Integer
|
function: Integer
|
||||||
begin
|
begin
|
||||||
Inc(Self.FProcExecutionCount);
|
Inc(Self.FProcExecutionCount);
|
||||||
@@ -236,7 +236,7 @@ begin
|
|||||||
end );
|
end );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestMycInitStateFuncFuture.Test_FanIn_OneFutureWaitsForMultipleOthers;
|
procedure TTestMycGateFuncFuture.Test_FanIn_OneFutureWaitsForMultipleOthers;
|
||||||
var
|
var
|
||||||
LPrerequisiteFuture1, LPrerequisiteFuture2: IMycFuture<Integer>;
|
LPrerequisiteFuture1, LPrerequisiteFuture2: IMycFuture<Integer>;
|
||||||
LMainFuture: IMycFuture<string>;
|
LMainFuture: IMycFuture<string>;
|
||||||
@@ -250,10 +250,10 @@ begin
|
|||||||
FProcExecutionCount := 0; // Reset for this test
|
FProcExecutionCount := 0; // Reset for this test
|
||||||
|
|
||||||
// Gate Latch: MainFuture waits for this latch, which needs 2 notifications.
|
// Gate Latch: MainFuture waits for this latch, which needs 2 notifications.
|
||||||
LGateLatch := TState.CreateLatch(2); // [cite: 77, 212, 330]
|
LGateLatch := TLatch.Construct(2); // [cite: 77, 212, 330]
|
||||||
|
|
||||||
// Create MainFuture, AInitState is the GateLatch's state.
|
// Create MainFuture, AInitState is the GateLatch's state.
|
||||||
LMainFuture := TMycInitStateFuncFuture<string>.Create(FTaskFactory, LGateLatch.State,
|
LMainFuture := TMycGateFuncFuture<string>.Create(FTaskFactory, LGateLatch.State,
|
||||||
function: string
|
function: string
|
||||||
begin
|
begin
|
||||||
Inc(Self.FProcExecutionCount, 10); // Indicate MainFuture's proc ran
|
Inc(Self.FProcExecutionCount, 10); // Indicate MainFuture's proc ran
|
||||||
@@ -262,8 +262,8 @@ begin
|
|||||||
|
|
||||||
// Setup Prerequisite Futures
|
// Setup Prerequisite Futures
|
||||||
// PrerequisiteFuture1
|
// PrerequisiteFuture1
|
||||||
LInitStateP1 := TState.CreateLatch(1); // Controllable init state for PF1
|
LInitStateP1 := TLatch.Construct(1); // Controllable init state for PF1
|
||||||
LPrerequisiteFuture1 := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP1.State,
|
LPrerequisiteFuture1 := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP1.State,
|
||||||
function: Integer
|
function: Integer
|
||||||
begin
|
begin
|
||||||
Inc(Self.FProcExecutionCount, 1); // PF1 ran
|
Inc(Self.FProcExecutionCount, 1); // PF1 ran
|
||||||
@@ -273,8 +273,8 @@ begin
|
|||||||
Subscriptions[1] := LPrerequisiteFuture1.Done.Subscribe(LSub1); // Subscribe to PF1's completion [cite: 56, 188, 306]
|
Subscriptions[1] := LPrerequisiteFuture1.Done.Subscribe(LSub1); // Subscribe to PF1's completion [cite: 56, 188, 306]
|
||||||
|
|
||||||
// PrerequisiteFuture2
|
// PrerequisiteFuture2
|
||||||
LInitStateP2 := TState.CreateLatch(1); // Controllable init state for PF2
|
LInitStateP2 := TLatch.Construct(1); // Controllable init state for PF2
|
||||||
LPrerequisiteFuture2 := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP2.State,
|
LPrerequisiteFuture2 := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP2.State,
|
||||||
function: Integer
|
function: Integer
|
||||||
begin
|
begin
|
||||||
Inc(Self.FProcExecutionCount, 1); // PF2 ran
|
Inc(Self.FProcExecutionCount, 1); // PF2 ran
|
||||||
@@ -312,7 +312,7 @@ begin
|
|||||||
Subscriptions[2].Unsubscribe; //
|
Subscriptions[2].Unsubscribe; //
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestMycInitStateFuncFuture.Test_FanOut_MultipleFuturesWaitForOneTrigger;
|
procedure TTestMycGateFuncFuture.Test_FanOut_MultipleFuturesWaitForOneTrigger;
|
||||||
var
|
var
|
||||||
LTriggerLatch: IMycLatch;
|
LTriggerLatch: IMycLatch;
|
||||||
LFutureA, LFutureB: IMycFuture<Integer>;
|
LFutureA, LFutureB: IMycFuture<Integer>;
|
||||||
@@ -322,10 +322,10 @@ begin
|
|||||||
LFlagFutureBRan := False;
|
LFlagFutureBRan := False;
|
||||||
Self.FSharedCounter := 0; // Reset shared counter for this test
|
Self.FSharedCounter := 0; // Reset shared counter for this test
|
||||||
|
|
||||||
LTriggerLatch := TState.CreateLatch(1); // Single trigger [cite: 77, 212, 330]
|
LTriggerLatch := TLatch.Construct(1); // Single trigger [cite: 77, 212, 330]
|
||||||
|
|
||||||
// Future A
|
// Future A
|
||||||
LFutureA := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
LFutureA := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
||||||
function: Integer
|
function: Integer
|
||||||
begin
|
begin
|
||||||
LFlagFutureARan := True;
|
LFlagFutureARan := True;
|
||||||
@@ -334,7 +334,7 @@ begin
|
|||||||
end);
|
end);
|
||||||
|
|
||||||
// Future B
|
// Future B
|
||||||
LFutureB := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
LFutureB := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
||||||
function: Integer
|
function: Integer
|
||||||
begin
|
begin
|
||||||
LFlagFutureBRan := True;
|
LFlagFutureBRan := True;
|
||||||
@@ -364,5 +364,5 @@ end;
|
|||||||
|
|
||||||
initialization
|
initialization
|
||||||
// For DUnitX, attributes typically handle registration.
|
// For DUnitX, attributes typically handle registration.
|
||||||
// If needed for older DUnit: RegisterTest(TTestMycInitStateFuncFuture.Suite);
|
// If needed for older DUnit: RegisterTest(TTestMycGateFuncFuture.Suite);
|
||||||
end.
|
end.
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ var
|
|||||||
delayedGate: IMycLatch; // IMycLatch implements IMycState [cite: 58]
|
delayedGate: IMycLatch; // IMycLatch implements IMycState [cite: 58]
|
||||||
resultValue: Integer;
|
resultValue: Integer;
|
||||||
begin
|
begin
|
||||||
delayedGate := TState.CreateLatch( 1 ); // Create a latch that requires one notification to be set [cite: 66]
|
delayedGate := TLatch.Construct( 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 (IMycLatch) should not be nil.' ); // Static string
|
||||||
Assert.IsFalse( delayedGate.State.IsSet, 'The delayed gate should not be initially set.' ); // Static string [cite: 59, 55]
|
Assert.IsFalse( delayedGate.State.IsSet, 'The delayed gate should not be initially set.' ); // Static string [cite: 59, 55]
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ var
|
|||||||
delayedGate: IMycLatch;
|
delayedGate: IMycLatch;
|
||||||
resultValue: string;
|
resultValue: string;
|
||||||
begin
|
begin
|
||||||
delayedGate := TState.CreateLatch( 1 ); // [cite: 66]
|
delayedGate := TLatch.Construct( 1 ); // [cite: 66]
|
||||||
Assert.IsFalse( delayedGate.State.IsSet, 'The delayed gate for chain test should not be initially set.' );
|
Assert.IsFalse( delayedGate.State.IsSet, 'The delayed gate for chain test should not be initially set.' );
|
||||||
// Static string [cite: 59, 55]
|
// Static string [cite: 59, 55]
|
||||||
|
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ end;
|
|||||||
procedure TMycNotifierChaosStressTests.Test_MixedOperations_Stress;
|
procedure TMycNotifierChaosStressTests.Test_MixedOperations_Stress;
|
||||||
const
|
const
|
||||||
NumThreads = 24; // Number of concurrent worker threads
|
NumThreads = 24; // Number of concurrent worker threads
|
||||||
IterationsPerThread = 5000; // Number of random operations per thread
|
IterationsPerThread = 2000; // Number of random operations per thread
|
||||||
var
|
var
|
||||||
threads: array of TStressWorkerThread;
|
threads: array of TStressWorkerThread;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ end;
|
|||||||
procedure TMycNotifierThreadingTests.Test_ConcurrentAdvise_Then_UnadviseAll_Consistency;
|
procedure TMycNotifierThreadingTests.Test_ConcurrentAdvise_Then_UnadviseAll_Consistency;
|
||||||
const
|
const
|
||||||
NumThreads = 24; // Number of threads
|
NumThreads = 24; // Number of threads
|
||||||
ItemsPerThread = 2500; // Number of Advise operations per thread
|
ItemsPerThread = 250; // Number of Advise operations per thread
|
||||||
var
|
var
|
||||||
threads: array of TAdviseWorkerThread;
|
threads: array of TAdviseWorkerThread;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ end;
|
|||||||
|
|
||||||
function TTestMycDirtyFlag.CreateAndPrepareDirtyFlag(StartDirty: Boolean = True): IMycDirty;
|
function TTestMycDirtyFlag.CreateAndPrepareDirtyFlag(StartDirty: Boolean = True): IMycDirty;
|
||||||
begin
|
begin
|
||||||
Result := TState.CreateDirty; // Initially dirty
|
Result := TDirty.Construct; // Initially dirty
|
||||||
if not StartDirty then
|
if not StartDirty then
|
||||||
Result.Reset; // Reset to make it clean
|
Result.Reset; // Reset to make it clean
|
||||||
Assert.AreEqual(StartDirty, Result.State.IsSet, 'CreateAndPrepareDirtyFlag initial state incorrect.');
|
Assert.AreEqual(StartDirty, Result.State.IsSet, 'CreateAndPrepareDirtyFlag initial state incorrect.');
|
||||||
@@ -127,7 +127,7 @@ procedure TTestMycDirtyFlag.TestCreate_InitialStateIsDirty;
|
|||||||
var
|
var
|
||||||
dirtyFlag: IMycDirty;
|
dirtyFlag: IMycDirty;
|
||||||
begin
|
begin
|
||||||
dirtyFlag := TState.CreateDirty;
|
dirtyFlag := TDirty.Construct;
|
||||||
Assert.IsTrue(dirtyFlag.State.IsSet, 'Newly created dirty flag should be IsSet (dirty).');
|
Assert.IsTrue(dirtyFlag.State.IsSet, 'Newly created dirty flag should be IsSet (dirty).');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
+22
-22
@@ -124,7 +124,7 @@ var
|
|||||||
latch: IMycLatch;
|
latch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
// TMycLatch.CreateLatch returns TMycLatch.Null if InitialCount <= 0
|
// TMycLatch.CreateLatch returns TMycLatch.Null if InitialCount <= 0
|
||||||
latch := TState.CreateLatch(InitialCount);
|
latch := TLatch.Construct(InitialCount);
|
||||||
Assert.AreEqual(ExpectedIsSet, latch.State.IsSet, 'Latch initial IsSet state mismatch for count ' + IntToStr(InitialCount) + '.');
|
Assert.AreEqual(ExpectedIsSet, latch.State.IsSet, 'Latch initial IsSet state mismatch for count ' + IntToStr(InitialCount) + '.');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ var
|
|||||||
latch: IMycLatch;
|
latch: IMycLatch;
|
||||||
returnedValueFromNotify: Boolean;
|
returnedValueFromNotify: Boolean;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(InitialCount);
|
latch := TLatch.Construct(InitialCount);
|
||||||
returnedValueFromNotify := latch.Notify; // This is IMycLatch (as IMycSubscriber).Notify
|
returnedValueFromNotify := latch.Notify; // This is IMycLatch (as IMycSubscriber).Notify
|
||||||
|
|
||||||
Assert.AreEqual(ExpectedReturn, returnedValueFromNotify, 'Unexpected return value from Latch.Notify call for initial count ' + IntToStr(InitialCount) + '.');
|
Assert.AreEqual(ExpectedReturn, returnedValueFromNotify, 'Unexpected return value from Latch.Notify call for initial count ' + IntToStr(InitialCount) + '.');
|
||||||
@@ -144,7 +144,7 @@ procedure TTestMycLatch.TestNotify_DecrementsCounter_StateChanges;
|
|||||||
var
|
var
|
||||||
latch: IMycLatch;
|
latch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1);
|
latch := TLatch.Construct(1);
|
||||||
Assert.IsFalse(latch.State.IsSet, 'Latch should initially not be set (Count=1).');
|
Assert.IsFalse(latch.State.IsSet, 'Latch should initially not be set (Count=1).');
|
||||||
latch.Notify; // Count becomes 0
|
latch.Notify; // Count becomes 0
|
||||||
Assert.IsTrue(latch.State.IsSet, 'Latch should be set after Notify (Count became 0).');
|
Assert.IsTrue(latch.State.IsSet, 'Latch should be set after Notify (Count became 0).');
|
||||||
@@ -154,7 +154,7 @@ procedure TTestMycLatch.TestNotify_MultipleNotifies_CounterBecomesNegativeAndSta
|
|||||||
var
|
var
|
||||||
latch: IMycLatch;
|
latch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1);
|
latch := TLatch.Construct(1);
|
||||||
latch.Notify; // Count becomes 0, IsSet = True
|
latch.Notify; // Count becomes 0, IsSet = True
|
||||||
Assert.IsTrue(latch.State.IsSet, 'Latch should be set after first Notify.');
|
Assert.IsTrue(latch.State.IsSet, 'Latch should be set after first Notify.');
|
||||||
latch.Notify; // Count becomes -1, IsSet should remain True
|
latch.Notify; // Count becomes -1, IsSet should remain True
|
||||||
@@ -169,7 +169,7 @@ var
|
|||||||
mockSub: TMockSubscriber;
|
mockSub: TMockSubscriber;
|
||||||
subscription: TMycSubscription;
|
subscription: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1);
|
latch := TLatch.Construct(1);
|
||||||
mockSub := TMockSubscriber.Create;
|
mockSub := TMockSubscriber.Create;
|
||||||
subscription := latch.State.Subscribe(mockSub); // Subscribing to the Latch's state
|
subscription := latch.State.Subscribe(mockSub); // Subscribing to the Latch's state
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ var
|
|||||||
mockSub1, mockSub2, mockSub3: TMockSubscriber;
|
mockSub1, mockSub2, mockSub3: TMockSubscriber;
|
||||||
sub1, sub2, sub3: TMycSubscription; // Keep subscriptions in scope
|
sub1, sub2, sub3: TMycSubscription; // Keep subscriptions in scope
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1);
|
latch := TLatch.Construct(1);
|
||||||
mockSub1 := TMockSubscriber.Create;
|
mockSub1 := TMockSubscriber.Create;
|
||||||
mockSub2 := TMockSubscriber.Create;
|
mockSub2 := TMockSubscriber.Create;
|
||||||
mockSub3 := TMockSubscriber.Create;
|
mockSub3 := TMockSubscriber.Create;
|
||||||
@@ -210,7 +210,7 @@ var
|
|||||||
mockSub: TMockSubscriber;
|
mockSub: TMockSubscriber;
|
||||||
subscription: TMycSubscription;
|
subscription: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(2); // Count = 2
|
latch := TLatch.Construct(2); // Count = 2
|
||||||
mockSub := TMockSubscriber.Create;
|
mockSub := TMockSubscriber.Create;
|
||||||
subscription := latch.State.Subscribe(mockSub);
|
subscription := latch.State.Subscribe(mockSub);
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ var
|
|||||||
mockSub: TMockSubscriber;
|
mockSub: TMockSubscriber;
|
||||||
subscription: TMycSubscription;
|
subscription: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1);
|
latch := TLatch.Construct(1);
|
||||||
mockSub := TMockSubscriber.Create;
|
mockSub := TMockSubscriber.Create;
|
||||||
subscription := latch.State.Subscribe(mockSub);
|
subscription := latch.State.Subscribe(mockSub);
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ var
|
|||||||
mockSub1, mockSub2: TMockSubscriber;
|
mockSub1, mockSub2: TMockSubscriber;
|
||||||
subscription1, subscription2: TMycSubscription;
|
subscription1, subscription2: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1); // Create with count 1
|
latch := TLatch.Construct(1); // Create with count 1
|
||||||
mockSub1 := TMockSubscriber.Create;
|
mockSub1 := TMockSubscriber.Create;
|
||||||
subscription1 := latch.State.Subscribe(mockSub1); // Subscribe before set
|
subscription1 := latch.State.Subscribe(mockSub1); // Subscribe before set
|
||||||
|
|
||||||
@@ -270,8 +270,8 @@ var
|
|||||||
mockSubForB: TMockSubscriber;
|
mockSubForB: TMockSubscriber;
|
||||||
subHandle_B_listens_A, subHandle_Mock_listens_B: TMycSubscription;
|
subHandle_B_listens_A, subHandle_Mock_listens_B: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latchA := TState.CreateLatch(1);
|
latchA := TLatch.Construct(1);
|
||||||
latchB := TState.CreateLatch(1); // latchB is an IMycSubscriber
|
latchB := TLatch.Construct(1); // latchB is an IMycSubscriber
|
||||||
mockSubForB := TMockSubscriber.Create;
|
mockSubForB := TMockSubscriber.Create;
|
||||||
|
|
||||||
subHandle_Mock_listens_B := latchB.State.Subscribe(mockSubForB);
|
subHandle_Mock_listens_B := latchB.State.Subscribe(mockSubForB);
|
||||||
@@ -295,9 +295,9 @@ var
|
|||||||
mockSubForC: TMockSubscriber;
|
mockSubForC: TMockSubscriber;
|
||||||
sub_Mock_C, sub_C_B, sub_B_A: TMycSubscription;
|
sub_Mock_C, sub_C_B, sub_B_A: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latchA := TState.CreateLatch(1);
|
latchA := TLatch.Construct(1);
|
||||||
latchB := TState.CreateLatch(1);
|
latchB := TLatch.Construct(1);
|
||||||
latchC := TState.CreateLatch(1);
|
latchC := TLatch.Construct(1);
|
||||||
mockSubForC := TMockSubscriber.Create;
|
mockSubForC := TMockSubscriber.Create;
|
||||||
|
|
||||||
sub_Mock_C := latchC.State.Subscribe(mockSubForC);
|
sub_Mock_C := latchC.State.Subscribe(mockSubForC);
|
||||||
@@ -320,8 +320,8 @@ var
|
|||||||
begin
|
begin
|
||||||
// LatchA needs 2 notifies to become set. LatchB needs 1 notify to become set.
|
// LatchA needs 2 notifies to become set. LatchB needs 1 notify to become set.
|
||||||
// LatchB subscribes to LatchA. So LatchB will be notified once LatchA becomes set.
|
// LatchB subscribes to LatchA. So LatchB will be notified once LatchA becomes set.
|
||||||
latchA := TState.CreateLatch(2);
|
latchA := TLatch.Construct(2);
|
||||||
latchB := TState.CreateLatch(1);
|
latchB := TLatch.Construct(1);
|
||||||
mockSubForB := TMockSubscriber.Create;
|
mockSubForB := TMockSubscriber.Create;
|
||||||
|
|
||||||
sub_Mock_B := latchB.State.Subscribe(mockSubForB);
|
sub_Mock_B := latchB.State.Subscribe(mockSubForB);
|
||||||
@@ -347,7 +347,7 @@ var
|
|||||||
mockSub: TMockSubscriber;
|
mockSub: TMockSubscriber;
|
||||||
subscription: TMycSubscription;
|
subscription: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(0); // Returns TMycLatch.Null which is set.
|
latch := TLatch.Construct(0); // Returns TMycLatch.Null which is set.
|
||||||
mockSub := TMockSubscriber.Create;
|
mockSub := TMockSubscriber.Create;
|
||||||
|
|
||||||
subscription := latch.State.Subscribe(mockSub); // TMycLatch.Subscribe notifies immediately if already set.
|
subscription := latch.State.Subscribe(mockSub); // TMycLatch.Subscribe notifies immediately if already set.
|
||||||
@@ -362,7 +362,7 @@ var
|
|||||||
mockSub: TMockSubscriber;
|
mockSub: TMockSubscriber;
|
||||||
subscription: TMycSubscription;
|
subscription: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1);
|
latch := TLatch.Construct(1);
|
||||||
mockSub := TMockSubscriber.Create;
|
mockSub := TMockSubscriber.Create;
|
||||||
|
|
||||||
subscription := latch.State.Subscribe(mockSub);
|
subscription := latch.State.Subscribe(mockSub);
|
||||||
@@ -381,7 +381,7 @@ var
|
|||||||
mockSub: TMockSubscriber;
|
mockSub: TMockSubscriber;
|
||||||
subscription: TMycSubscription;
|
subscription: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(3);
|
latch := TLatch.Construct(3);
|
||||||
|
|
||||||
latch.Notify; // Count -> 2
|
latch.Notify; // Count -> 2
|
||||||
latch.Notify; // Count -> 1
|
latch.Notify; // Count -> 1
|
||||||
@@ -404,7 +404,7 @@ var
|
|||||||
mockSub1, mockSub2: TMockSubscriber;
|
mockSub1, mockSub2: TMockSubscriber;
|
||||||
subscription1, subscription2: TMycSubscription;
|
subscription1, subscription2: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1);
|
latch := TLatch.Construct(1);
|
||||||
mockSub1 := TMockSubscriber.Create;
|
mockSub1 := TMockSubscriber.Create;
|
||||||
mockSub2 := TMockSubscriber.Create;
|
mockSub2 := TMockSubscriber.Create;
|
||||||
|
|
||||||
@@ -432,7 +432,7 @@ var
|
|||||||
mockSub: TMockSubscriber;
|
mockSub: TMockSubscriber;
|
||||||
// 'subscription' will be declared in an inner scope to control its finalization
|
// 'subscription' will be declared in an inner scope to control its finalization
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1);
|
latch := TLatch.Construct(1);
|
||||||
mockSub := TMockSubscriber.Create;
|
mockSub := TMockSubscriber.Create;
|
||||||
|
|
||||||
var noException: Boolean := True;
|
var noException: Boolean := True;
|
||||||
@@ -468,7 +468,7 @@ var
|
|||||||
mockSubInitial, mockSubNew: TMockSubscriber;
|
mockSubInitial, mockSubNew: TMockSubscriber;
|
||||||
subscriptionInitial, subscriptionNew: TMycSubscription;
|
subscriptionInitial, subscriptionNew: TMycSubscription;
|
||||||
begin
|
begin
|
||||||
latch := TState.CreateLatch(1);
|
latch := TLatch.Construct(1);
|
||||||
mockSubInitial := TMockSubscriber.Create;
|
mockSubInitial := TMockSubscriber.Create;
|
||||||
subscriptionInitial := latch.State.Subscribe(mockSubInitial);
|
subscriptionInitial := latch.State.Subscribe(mockSubInitial);
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -91,7 +91,7 @@ var
|
|||||||
jobCompletedLatch: IMycLatch;
|
jobCompletedLatch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
jobExecuted := False;
|
jobExecuted := False;
|
||||||
jobCompletedLatch := TMycLatch.CreateLatch(1); // Changed from Signals.CreateLatch
|
jobCompletedLatch := TLatch.Construct(1); // Changed from Signals.CreateLatch
|
||||||
|
|
||||||
FFactory.Run(
|
FFactory.Run(
|
||||||
procedure
|
procedure
|
||||||
@@ -111,7 +111,7 @@ var
|
|||||||
subscriber: IMycSubscriber;
|
subscriber: IMycSubscriber;
|
||||||
begin
|
begin
|
||||||
jobExecuted := False;
|
jobExecuted := False;
|
||||||
jobCompletedLatch := TMycLatch.CreateLatch(1); // Changed from Signals.CreateLatch
|
jobCompletedLatch := TLatch.Construct(1); // Changed from Signals.CreateLatch
|
||||||
|
|
||||||
subscriber := FFactory.Run(
|
subscriber := FFactory.Run(
|
||||||
procedure
|
procedure
|
||||||
@@ -122,7 +122,7 @@ begin
|
|||||||
|
|
||||||
Assert.IsNotNull(subscriber, 'Run should return a subscriber for delayed job');
|
Assert.IsNotNull(subscriber, 'Run should return a subscriber for delayed job');
|
||||||
// Use TMycLatch.Null for comparison
|
// Use TMycLatch.Null for comparison
|
||||||
Assert.AreNotEqual<IMycSubscriber>(TMycLatch.Null, subscriber, 'Subscriber should not be TMycLatch.Null for StartCount > 0');
|
Assert.AreNotEqual<IMycSubscriber>(TLatch.Null, subscriber, 'Subscriber should not be TMycLatch.Null for StartCount > 0');
|
||||||
|
|
||||||
subscriber.Notify;
|
subscriber.Notify;
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ var
|
|||||||
startTime, endTime: Cardinal;
|
startTime, endTime: Cardinal;
|
||||||
begin
|
begin
|
||||||
// TMycLatch.CreateLatch(0) will return TMycLatch.Null
|
// TMycLatch.CreateLatch(0) will return TMycLatch.Null
|
||||||
alreadySetLatch := TMycLatch.CreateLatch(0); // Changed from Signals.CreateLatch
|
alreadySetLatch := TLatch.Construct(0); // Changed from Signals.CreateLatch
|
||||||
Assert.IsTrue(alreadySetLatch.State.IsSet, 'Latch should be initially set');
|
Assert.IsTrue(alreadySetLatch.State.IsSet, 'Latch should be initially set');
|
||||||
|
|
||||||
startTime := TThread.GetTickCount;
|
startTime := TThread.GetTickCount;
|
||||||
@@ -155,7 +155,7 @@ var
|
|||||||
begin
|
begin
|
||||||
inMainThreadInJob := True;
|
inMainThreadInJob := True;
|
||||||
inWorkerThreadInJob := False;
|
inWorkerThreadInJob := False;
|
||||||
jobDoneLatch := TMycLatch.CreateLatch(1); // Changed from Signals.CreateLatch
|
jobDoneLatch := TLatch.Construct(1); // Changed from Signals.CreateLatch
|
||||||
|
|
||||||
Assert.IsTrue(FFactory.InMainThread, 'Test method itself should be in main thread');
|
Assert.IsTrue(FFactory.InMainThread, 'Test method itself should be in main thread');
|
||||||
Assert.IsFalse(FFactory.InWorkerThread, 'Test method itself should not be in a factory worker thread');
|
Assert.IsFalse(FFactory.InWorkerThread, 'Test method itself should not be in a factory worker thread');
|
||||||
@@ -178,7 +178,7 @@ procedure TMycTaskFactoryTests.TestExceptionPropagationFromJob;
|
|||||||
var
|
var
|
||||||
jobDoneLatch: IMycLatch;
|
jobDoneLatch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
jobDoneLatch := TMycLatch.CreateLatch(1);
|
jobDoneLatch := TLatch.Construct(1);
|
||||||
|
|
||||||
FFactory.EnqueueJob(
|
FFactory.EnqueueJob(
|
||||||
procedure
|
procedure
|
||||||
@@ -229,8 +229,8 @@ var
|
|||||||
dummyStateToWaitFor: IMycState;
|
dummyStateToWaitFor: IMycState;
|
||||||
begin
|
begin
|
||||||
exceptionCaughtInJob := False;
|
exceptionCaughtInJob := False;
|
||||||
jobDoneLatch := TMycLatch.CreateLatch(1);
|
jobDoneLatch := TLatch.Construct(1);
|
||||||
dummyStateToWaitFor := TMycLatch.CreateLatch(1).State;
|
dummyStateToWaitFor := TLatch.Construct(1).State;
|
||||||
|
|
||||||
FFactory.EnqueueJob(
|
FFactory.EnqueueJob(
|
||||||
procedure
|
procedure
|
||||||
|
|||||||
Reference in New Issue
Block a user