Refactoring
This commit is contained in:
@@ -37,7 +37,7 @@ constructor TMycInitStateFuncFuture<T>.Create( const ATaskManager: IMycTaskManag
|
|||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
FDone := TMycLatch.CreateLatch( 1 );
|
FDone := State.CreateLatch( 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.
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
Myc.Core.Signals;
|
||||||
|
|
||||||
type
|
type
|
||||||
TMycPendingJob = class(TInterfacedObject, IMycSubscriber)
|
TMycPendingJob = class(TInterfacedObject, IMycSubscriber)
|
||||||
private
|
private
|
||||||
|
|||||||
+58
-367
@@ -3,211 +3,91 @@ unit Myc.Signals;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
System.SysUtils, Myc.Core.Notifier;
|
System.SysUtils;
|
||||||
|
|
||||||
type
|
type
|
||||||
IMycState = interface;
|
|
||||||
|
|
||||||
IMycSubscriber = interface
|
IMycSubscriber = interface
|
||||||
// Interface for an entity that can be notified by a signal or latch.
|
// Interface for an entity that can be notified by a State or State.
|
||||||
// Returns true if this subscriber expects further notifications from the source, false otherwise.
|
// Returns true if this subscriber expects further notifications from the source, false otherwise.
|
||||||
function Notify: Boolean;
|
function Notify: Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TMycState = class;
|
IMycState = interface;
|
||||||
|
|
||||||
TMycSubscription = record
|
TMycSubscription = record
|
||||||
private
|
private
|
||||||
FState: IMycState;
|
FState: IMycState;
|
||||||
FTag: TMycNotifyList<IMycSubscriber>.TTag; // Tag identifying this subscription within the notifier list.
|
FTag: Pointer; // Tag identifying this subscription within the notifier list.
|
||||||
function GetState: IMycState;
|
function GetState: IMycState;
|
||||||
public
|
public
|
||||||
constructor Create(const AState: IMycState; ATag: TMycNotifyList<IMycSubscriber>.TTag);
|
constructor Create( const AState: IMycState; ATag: Pointer );
|
||||||
// Unsubscribes from the associated signal.
|
// Unsubscribes from the associated State.
|
||||||
procedure Unsubscribe;
|
procedure Unsubscribe;
|
||||||
class operator Initialize(out Dest: TMycSubscription);
|
class operator Initialize( out Dest: TMycSubscription );
|
||||||
property State: IMycState read GetState;
|
property State: IMycState read GetState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IMycState = interface
|
IMycState = interface
|
||||||
// Represents a subscribable state that can be queried.
|
// Represents a subscribable state that can be queried.
|
||||||
{$region 'property access'}
|
{$REGION 'property access'}
|
||||||
function GetIsSet: Boolean;
|
function GetIsSet: Boolean;
|
||||||
{$endregion}
|
{$ENDREGION}
|
||||||
// Subscribes a given subscriber to this signal.
|
// Subscribes a given subscriber to this State.
|
||||||
function Subscribe(const Subscriber: IMycSubscriber): TMycSubscription;
|
function Subscribe( Subscriber: IMycSubscriber ): TMycSubscription;
|
||||||
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag);
|
procedure Unsubscribe( Tag: Pointer );
|
||||||
// IsSet is true if the state has been reached or the condition is met.
|
// IsSet is true if the state has been reached or the condition is met.
|
||||||
property IsSet: Boolean read GetIsSet;
|
property IsSet: Boolean read GetIsSet;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TMycState = class abstract( TInterfacedObject, IMycState )
|
|
||||||
strict private
|
|
||||||
class var
|
|
||||||
FNull: IMycState;
|
|
||||||
class constructor ClassCreate;
|
|
||||||
protected
|
|
||||||
function GetIsSet: Boolean; virtual; abstract;
|
|
||||||
public
|
|
||||||
function Subscribe(const Subscriber: IMycSubscriber): TMycSubscription; virtual; abstract;
|
|
||||||
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag); virtual; abstract;
|
|
||||||
property IsSet: Boolean read GetIsSet;
|
|
||||||
// Provides access to the singleton null latch instance (always set).
|
|
||||||
class property Null: IMycState read FNull;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// IMycFlag represents a base for signal-like objects that have a binary state (set/not set),
|
|
||||||
// can be notified (as an IMycSubscriber) to potentially change state,
|
|
||||||
// and whose state (IMycState) can be queried and subscribed to.
|
|
||||||
IMycFlag = interface(IMycSubscriber)
|
|
||||||
{$region 'property access'}
|
|
||||||
// Provides access to the IMycState interface of the flag.
|
|
||||||
function GetState: IMycState;
|
|
||||||
{$endregion}
|
|
||||||
property State: IMycState read GetState;
|
|
||||||
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(IMycFlag)
|
IMycLatch = interface( IMycSubscriber )
|
||||||
|
// Provides access to the IMycState interface of the flag.
|
||||||
|
function GetState: IMycState;
|
||||||
|
property State: IMycState read GetState;
|
||||||
// Inherits IMycSubscriber and State property from IMycFlag. No new members.
|
// Inherits IMycSubscriber and State property from IMycFlag. No new members.
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// TMycLatch implements a countdown latch.
|
|
||||||
// It is initialized with a count. Calls to its Notify method (as an IMycSubscriber)
|
|
||||||
// decrement this count. When the count reaches zero, the latch transitions to the "set"
|
|
||||||
// state (IsSet becomes true), notifies its current subscribers once, and then remains set.
|
|
||||||
TMycLatch = class(TMycState, IMycLatch, IMycFlag)
|
|
||||||
strict private
|
|
||||||
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
|
|
||||||
[volatile] FCount: Integer; // The internal countdown value for the latch.
|
|
||||||
function GetState: IMycState; // Implementation for IMycLatch.GetState and IMycFlag.GetState.
|
|
||||||
protected
|
|
||||||
function GetIsSet: Boolean; override; final; // Implementation for IMycState.GetIsSet.
|
|
||||||
public
|
|
||||||
// Creates the latch with an initial count.
|
|
||||||
// If ACount is 0 or less, the latch is effectively pre-set (delegates to FNull via CreateLatch factory).
|
|
||||||
constructor Create(ACount: Integer);
|
|
||||||
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
|
|
||||||
function Subscribe(const Subscriber: IMycSubscriber): TMycSubscription; override;
|
|
||||||
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag); override;
|
|
||||||
|
|
||||||
// IMycSubscriber implementation for TMycLatch itself.
|
|
||||||
// Decrements the internal count. If the count reaches zero,
|
|
||||||
// registered subscribers are notified, and the latch becomes permanently set.
|
|
||||||
function Notify: Boolean;
|
|
||||||
|
|
||||||
// Provides access to the singleton null latch instance (always set).
|
|
||||||
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(IMycFlag)
|
IMycDirty = interface( IMycSubscriber )
|
||||||
|
// Provides access to the IMycState interface of the flag.
|
||||||
|
function GetState: IMycState;
|
||||||
// Resets the flag to its "clean" (not set / not dirty) state.
|
// Resets the flag to its "clean" (not set / not dirty) state.
|
||||||
// Returns true if the flag was actually dirty before this reset, false otherwise.
|
// Returns true if the flag was actually dirty before this reset, false otherwise.
|
||||||
function Reset: Boolean;
|
function Reset: Boolean;
|
||||||
|
property State: IMycState read GetState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// TMycDirty implements a resettable "dirty flag".
|
State = record
|
||||||
// It can be explicitly set to dirty (via Notify) or reset to clean (via Reset).
|
|
||||||
// Subscribers are notified of relevant state changes.
|
|
||||||
TMycDirty = class(TMycState, IMycFlag, IMycDirty)
|
|
||||||
strict private
|
|
||||||
FSubscribers: TMycNotifyList<IMycSubscriber>; // List of subscribers interested in state changes of this dirty flag.
|
|
||||||
private
|
private
|
||||||
[volatile] FFlag: Boolean; // Internal state: true if dirty/set, false if clean/reset.
|
class function GetNull: IMycState; static;
|
||||||
function GetState: IMycState; // Implementation for IMycFlag.GetState.
|
|
||||||
protected
|
|
||||||
function GetIsSet: Boolean; override; final; // Implementation for IMycState.GetIsSet (true if dirty).
|
|
||||||
public
|
public
|
||||||
// Creates a new dirty flag, initially set to dirty (true).
|
class function CreateLatch( Count: Integer ): IMycLatch; static;
|
||||||
constructor Create;
|
|
||||||
destructor Destroy; override;
|
|
||||||
|
|
||||||
// Factory method to create a new TMycDirty instance.
|
|
||||||
class function CreateDirty: IMycDirty; static;
|
class function CreateDirty: IMycDirty; static;
|
||||||
|
class function All( const States: TArray<IMycState> ): IMycState; static;
|
||||||
// IMycSignal implementation
|
class function Any( const States: TArray<IMycState> ): IMycState; static;
|
||||||
function Subscribe(const Subscriber: IMycSubscriber): TMycSubscription; override;
|
class property Null: IMycState read GetNull;
|
||||||
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag); override;
|
|
||||||
|
|
||||||
// IMycSubscriber implementation for TMycDirty.
|
|
||||||
// Sets this flag to dirty (true). Notifies subscribers if it transitioned from clean to dirty.
|
|
||||||
function Notify: Boolean;
|
|
||||||
|
|
||||||
// IMycDirty implementation. Resets the flag to clean (false).
|
|
||||||
function Reset: Boolean;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
System.SyncObjs; // For TInterlocked
|
Myc.Core.Notifier, Myc.Core.Signals;
|
||||||
|
|
||||||
type
|
|
||||||
// TMycNullState implements a "null object" pattern for IMycState.
|
|
||||||
// This state is always considered "set".
|
|
||||||
TMycNullState = class(TInterfacedObject, IMycState)
|
|
||||||
protected
|
|
||||||
// IMycState
|
|
||||||
function GetIsSet: Boolean;
|
|
||||||
function Subscribe(const Subscriber: IMycSubscriber): TMycSubscription;
|
|
||||||
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag);
|
|
||||||
public
|
|
||||||
constructor Create;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TMycNullState }
|
|
||||||
|
|
||||||
constructor TMycNullState.Create;
|
|
||||||
begin
|
|
||||||
inherited Create;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMycNullState.GetIsSet: Boolean;
|
|
||||||
begin
|
|
||||||
Result := true; // Null state is always set.
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMycNullState.Subscribe(const Subscriber: IMycSubscriber): TMycSubscription;
|
|
||||||
begin
|
|
||||||
// Since the state is always set, notify the subscriber immediately.
|
|
||||||
if Assigned(Subscriber) then
|
|
||||||
begin
|
|
||||||
Subscriber.Notify;
|
|
||||||
end;
|
|
||||||
// No ongoing subscription is necessary or meaningful for a null state.
|
|
||||||
Result.Create(Self, nil); // Return an empty subscription.
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TMycNullState.Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag);
|
|
||||||
begin
|
|
||||||
// Unsubscribing from a null state has no effect.
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TMycSubscription }
|
{ TMycSubscription }
|
||||||
|
|
||||||
constructor TMycSubscription.Create(const AState: IMycState; ATag:
|
constructor TMycSubscription.Create( const AState: IMycState; ATag:
|
||||||
TMycNotifyList<IMycSubscriber>.TTag);
|
TMycNotifyList<IMycSubscriber>.TTag );
|
||||||
begin
|
begin
|
||||||
Assert( Assigned(AState) );
|
Assert( Assigned( AState ) );
|
||||||
FState := AState;
|
FState := AState;
|
||||||
FTag := ATag;
|
FTag := ATag;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMycSubscription.Unsubscribe;
|
procedure TMycSubscription.Unsubscribe;
|
||||||
begin
|
begin
|
||||||
FState.Unsubscribe(FTag);
|
FState.Unsubscribe( FTag );
|
||||||
FState := TMycState.Null;
|
FState := TMycState.Null;
|
||||||
FTag := nil;
|
FTag := nil;
|
||||||
end;
|
end;
|
||||||
@@ -217,243 +97,54 @@ begin
|
|||||||
Result := FState
|
Result := FState
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class operator TMycSubscription.Initialize(out Dest: TMycSubscription);
|
class operator TMycSubscription.Initialize( out Dest: TMycSubscription );
|
||||||
begin
|
begin
|
||||||
Dest.FState := TMycState.Null;
|
Dest.FState := TMycState.Null;
|
||||||
Dest.FTag := nil;
|
Dest.FTag := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TMycLatch }
|
{ State }
|
||||||
|
|
||||||
constructor TMycLatch.Create(ACount: Integer);
|
class function State.CreateLatch( Count: Integer ): IMycLatch;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
Result := TMycLatch.CreateLatch( Count );
|
||||||
Assert( ACount >= 0 );
|
|
||||||
FCount := ACount;
|
|
||||||
FSubscribers.Create;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class constructor TMycLatch.ClassCreate;
|
class function State.All( const States: TArray<IMycState> ): IMycState;
|
||||||
|
var
|
||||||
|
Latch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
// Create a singleton null latch instance that is initially (and always) set.
|
Latch := CreateLatch( Length( States ) );
|
||||||
FNull := TMycLatch.Create(0); // Calls the instance constructor
|
for var i := 0 to High( States ) do
|
||||||
|
States[i].Subscribe( Latch );
|
||||||
|
Result := Latch.State;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TMycLatch.Destroy;
|
class function State.Any( const States: TArray<IMycState> ): IMycState;
|
||||||
|
var
|
||||||
|
Latch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
FSubscribers.Destroy;
|
if Length( States ) = 0 then
|
||||||
inherited;
|
begin
|
||||||
end;
|
Result := State.Null;
|
||||||
|
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
|
else
|
||||||
Result := FNull;
|
begin
|
||||||
end;
|
Latch := CreateLatch( 1 );
|
||||||
|
for var i := 0 to High( States ) do
|
||||||
function TMycLatch.Notify: Boolean;
|
States[i].Subscribe( Latch );
|
||||||
var
|
Result := Latch.State;
|
||||||
currentCountAfterDecrement: Integer;
|
|
||||||
shouldNotifySubscribers: Boolean;
|
|
||||||
begin
|
|
||||||
FSubscribers.Lock;
|
|
||||||
try
|
|
||||||
currentCountAfterDecrement := TInterlocked.Decrement(FCount);
|
|
||||||
|
|
||||||
if currentCountAfterDecrement < -MaxInt div 2 then
|
|
||||||
TInterlocked.Increment(FCount); // Defend against extreme underflow.
|
|
||||||
|
|
||||||
shouldNotifySubscribers := (currentCountAfterDecrement = 0); // Notify only on transition to zero.
|
|
||||||
|
|
||||||
if shouldNotifySubscribers then
|
|
||||||
begin
|
|
||||||
FSubscribers.Notify(
|
|
||||||
function(Subscriber: IMycSubscriber): Boolean
|
|
||||||
begin
|
|
||||||
Result := Subscriber.Notify;
|
|
||||||
end);
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Returns true if the latch has not yet been set by this Notify call (count > 0).
|
|
||||||
Result := currentCountAfterDecrement > 0;
|
|
||||||
|
|
||||||
// If the latch is now set (or was already set), unadvise all subscribers.
|
|
||||||
// This ensures one-shot notification for the current set of subscribers.
|
|
||||||
if currentCountAfterDecrement <= 0 then
|
|
||||||
FSubscribers.UnadviseAll;
|
|
||||||
finally
|
|
||||||
FSubscribers.Release;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMycLatch.GetIsSet: Boolean;
|
class function State.CreateDirty: IMycDirty;
|
||||||
begin
|
begin
|
||||||
// The latch is set if its count has reached zero or less.
|
Result := TMycDirty.CreateDirty;
|
||||||
Result := FCount <= 0;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMycLatch.GetState: IMycState;
|
class function State.GetNull: IMycState;
|
||||||
begin
|
begin
|
||||||
// TMycLatch itself implements IMycState.
|
Result := TMycState.Null;
|
||||||
exit(Self);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMycLatch.Subscribe(const Subscriber: IMycSubscriber): TMycSubscription;
|
|
||||||
var
|
|
||||||
alreadySet: Boolean;
|
|
||||||
begin
|
|
||||||
if not Assigned(Subscriber) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
Subscriber._AddRef; // Manage ref count during this method's logic.
|
|
||||||
try
|
|
||||||
FSubscribers.Lock;
|
|
||||||
try
|
|
||||||
alreadySet := (FCount <= 0); // Check if latch is already set.
|
|
||||||
|
|
||||||
if alreadySet then
|
|
||||||
begin
|
|
||||||
// If already set, notify immediately; no persistent subscription needed.
|
|
||||||
Subscriber.Notify;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
// If not yet set, advise the subscriber.
|
|
||||||
Result.Create(Self, FSubscribers.Advise(Subscriber));
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
FSubscribers.Release;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
Subscriber._Release;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TMycLatch.Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag);
|
|
||||||
begin
|
|
||||||
if Tag = nil then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
FSubscribers.Lock;
|
|
||||||
try
|
|
||||||
FSubscribers.Unadvise(Tag);
|
|
||||||
finally
|
|
||||||
FSubscribers.Release;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TMycDirty }
|
|
||||||
|
|
||||||
constructor TMycDirty.Create;
|
|
||||||
begin
|
|
||||||
inherited Create;
|
|
||||||
FFlag := true; // A new dirty flag is initially considered dirty.
|
|
||||||
FSubscribers.Create;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TMycDirty.CreateDirty: IMycDirty;
|
|
||||||
begin
|
|
||||||
// Factory method to create a new TMycDirty instance.
|
|
||||||
Result := TMycDirty.Create;
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TMycDirty.Destroy;
|
|
||||||
begin
|
|
||||||
FSubscribers.Destroy; // Clean up the subscriber list.
|
|
||||||
inherited;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMycDirty.Reset: Boolean;
|
|
||||||
begin
|
|
||||||
// Sets the flag to false (clean) and returns true if it was previously true (dirty).
|
|
||||||
Result := TInterlocked.Exchange(FFlag, false);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMycDirty.GetIsSet: Boolean;
|
|
||||||
begin
|
|
||||||
// IsSet is true if the flag is dirty (FFlag = true).
|
|
||||||
Result := FFlag;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMycDirty.GetState: IMycState;
|
|
||||||
begin
|
|
||||||
// TMycDirty itself implements IMycState.
|
|
||||||
exit(Self);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMycDirty.Notify: Boolean;
|
|
||||||
var
|
|
||||||
wasPreviouslyClean: Boolean;
|
|
||||||
begin
|
|
||||||
FSubscribers.Lock;
|
|
||||||
try
|
|
||||||
// Set the flag to true (dirty) and check if it was previously false (clean).
|
|
||||||
wasPreviouslyClean := not TInterlocked.Exchange(FFlag, true);
|
|
||||||
|
|
||||||
if wasPreviouslyClean then // Only notify subscribers if state changed from clean to dirty.
|
|
||||||
begin
|
|
||||||
FSubscribers.Notify(
|
|
||||||
function(Subscriber: IMycSubscriber): Boolean
|
|
||||||
begin
|
|
||||||
Result := Subscriber.Notify;
|
|
||||||
end);
|
|
||||||
end;
|
|
||||||
// The return value of this Notify (as an IMycSubscriber) indicates if this
|
|
||||||
// TMycDirty instance itself would want more notifications if it were subscribed to something.
|
|
||||||
// Here, it reflects whether a state change to dirty occurred due to this call.
|
|
||||||
Result := wasPreviouslyClean;
|
|
||||||
finally
|
|
||||||
FSubscribers.Release;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMycDirty.Subscribe(const Subscriber: IMycSubscriber): TMycSubscription;
|
|
||||||
begin
|
|
||||||
if not Assigned(Subscriber) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
// For TMycDirty, we always add the subscriber and then check if we need to notify immediately.
|
|
||||||
// Ref counting for the subscriber interface is assumed to be handled by TMycNotifyList.Advise/Unadvise.
|
|
||||||
// Or, if explicit management is needed like in TMycLatch, it should be added.
|
|
||||||
// For consistency with TMycLatch, let's add AddRef/Release here too.
|
|
||||||
Subscriber._AddRef;
|
|
||||||
try
|
|
||||||
FSubscribers.Lock;
|
|
||||||
try
|
|
||||||
// Add subscriber regardless of current state.
|
|
||||||
Result.Create(Self, FSubscribers.Advise(Subscriber));
|
|
||||||
if FFlag then // If currently dirty, notify the new subscriber immediately.
|
|
||||||
begin
|
|
||||||
Subscriber.Notify;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
FSubscribers.Release;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
Subscriber._Release;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TMycDirty.Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag);
|
|
||||||
begin
|
|
||||||
if Tag = nil then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
FSubscribers.Lock;
|
|
||||||
try
|
|
||||||
FSubscribers.Unadvise(Tag);
|
|
||||||
finally
|
|
||||||
FSubscribers.Release;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
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;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|||||||
+2
-1
@@ -26,7 +26,8 @@ uses
|
|||||||
Myc.Futures in '..\Src\Myc.Futures.pas',
|
Myc.Futures in '..\Src\Myc.Futures.pas',
|
||||||
TestFutures in 'TestFutures.pas',
|
TestFutures in 'TestFutures.pas',
|
||||||
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';
|
||||||
|
|
||||||
{ 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}
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ $(PostBuildEvent)]]></PostBuildEvent>
|
|||||||
<DCCReference Include="TestFutures.pas"/>
|
<DCCReference Include="TestFutures.pas"/>
|
||||||
<DCCReference Include="..\Src\Myc.TaskManager.pas"/>
|
<DCCReference Include="..\Src\Myc.TaskManager.pas"/>
|
||||||
<DCCReference Include="..\Src\Myc.Core.Futures.pas"/>
|
<DCCReference Include="..\Src\Myc.Core.Futures.pas"/>
|
||||||
|
<DCCReference Include="..\Src\Myc.Core.Signals.pas"/>
|
||||||
<BuildConfiguration Include="Base">
|
<BuildConfiguration Include="Base">
|
||||||
<Key>Base</Key>
|
<Key>Base</Key>
|
||||||
</BuildConfiguration>
|
</BuildConfiguration>
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ const
|
|||||||
CExpectedResult = 42;
|
CExpectedResult = 42;
|
||||||
begin
|
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 := TMycLatch.Null.State; // Get IMycState from IMycLatch [cite: 61, 196, 314]
|
LInitStateAsState := State.Null;
|
||||||
|
|
||||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateAsState,
|
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateAsState,
|
||||||
function: Integer
|
function: Integer
|
||||||
@@ -120,7 +120,7 @@ var
|
|||||||
const
|
const
|
||||||
CExpectedResult = 'ChainCompleted';
|
CExpectedResult = 'ChainCompleted';
|
||||||
begin
|
begin
|
||||||
LInitLatch := TMycLatch.CreateLatch(1); // Create an init state that is not yet set [cite: 77, 212, 330]
|
LInitLatch := State.CreateLatch(1); // Create an init state that is not yet set [cite: 77, 212, 330]
|
||||||
|
|
||||||
LFuture := TMycInitStateFuncFuture<string>.Create(FTaskFactory, LInitLatch.State,
|
LFuture := TMycInitStateFuncFuture<string>.Create(FTaskFactory, LInitLatch.State,
|
||||||
function: string
|
function: string
|
||||||
@@ -155,7 +155,7 @@ const
|
|||||||
begin
|
begin
|
||||||
LExpectedExceptionRaisedByFactory := False;
|
LExpectedExceptionRaisedByFactory := False;
|
||||||
LLocalTaskFactory := TMycTaskFactory.Create;
|
LLocalTaskFactory := TMycTaskFactory.Create;
|
||||||
LInitStateAsState := TMycLatch.Null.State; // Immediate execution
|
LInitStateAsState := State.Null; // Immediate execution
|
||||||
|
|
||||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(LLocalTaskFactory, LInitStateAsState,
|
LFuture := TMycInitStateFuncFuture<Integer>.Create(LLocalTaskFactory, LInitStateAsState,
|
||||||
function: Integer
|
function: Integer
|
||||||
@@ -208,7 +208,7 @@ var
|
|||||||
LFuture: IMycFuture<Integer>;
|
LFuture: IMycFuture<Integer>;
|
||||||
LInitLatch: IMycLatch;
|
LInitLatch: IMycLatch;
|
||||||
begin
|
begin
|
||||||
LInitLatch := TMycLatch.CreateLatch(1);
|
LInitLatch := State.CreateLatch(1);
|
||||||
|
|
||||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitLatch.State,
|
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitLatch.State,
|
||||||
function: Integer
|
function: Integer
|
||||||
@@ -250,7 +250,7 @@ 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 := TMycLatch.CreateLatch(2); // [cite: 77, 212, 330]
|
LGateLatch := State.CreateLatch(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 := TMycInitStateFuncFuture<string>.Create(FTaskFactory, LGateLatch.State,
|
||||||
@@ -262,7 +262,7 @@ begin
|
|||||||
|
|
||||||
// Setup Prerequisite Futures
|
// Setup Prerequisite Futures
|
||||||
// PrerequisiteFuture1
|
// PrerequisiteFuture1
|
||||||
LInitStateP1 := TMycLatch.CreateLatch(1); // Controllable init state for PF1
|
LInitStateP1 := State.CreateLatch(1); // Controllable init state for PF1
|
||||||
LPrerequisiteFuture1 := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP1.State,
|
LPrerequisiteFuture1 := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP1.State,
|
||||||
function: Integer
|
function: Integer
|
||||||
begin
|
begin
|
||||||
@@ -273,7 +273,7 @@ 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 := TMycLatch.CreateLatch(1); // Controllable init state for PF2
|
LInitStateP2 := State.CreateLatch(1); // Controllable init state for PF2
|
||||||
LPrerequisiteFuture2 := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP2.State,
|
LPrerequisiteFuture2 := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP2.State,
|
||||||
function: Integer
|
function: Integer
|
||||||
begin
|
begin
|
||||||
@@ -322,7 +322,7 @@ begin
|
|||||||
LFlagFutureBRan := False;
|
LFlagFutureBRan := False;
|
||||||
Self.FSharedCounter := 0; // Reset shared counter for this test
|
Self.FSharedCounter := 0; // Reset shared counter for this test
|
||||||
|
|
||||||
LTriggerLatch := TMycLatch.CreateLatch(1); // Single trigger [cite: 77, 212, 330]
|
LTriggerLatch := State.CreateLatch(1); // Single trigger [cite: 77, 212, 330]
|
||||||
|
|
||||||
// Future A
|
// Future A
|
||||||
LFutureA := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
LFutureA := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ end;
|
|||||||
|
|
||||||
function TTestMycDirtyFlag.CreateAndPrepareDirtyFlag(StartDirty: Boolean = True): IMycDirty;
|
function TTestMycDirtyFlag.CreateAndPrepareDirtyFlag(StartDirty: Boolean = True): IMycDirty;
|
||||||
begin
|
begin
|
||||||
Result := TMycDirty.CreateDirty; // Initially dirty
|
Result := State.CreateDirty; // 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 := TMycDirty.CreateDirty;
|
dirtyFlag := State.CreateDirty;
|
||||||
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 := TMycLatch.CreateLatch(InitialCount);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(InitialCount);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(2); // Count = 2
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1); // Create with count 1
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latchA := State.CreateLatch(1);
|
||||||
latchB := TMycLatch.CreateLatch(1); // latchB is an IMycSubscriber
|
latchB := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latchA := State.CreateLatch(1);
|
||||||
latchB := TMycLatch.CreateLatch(1);
|
latchB := State.CreateLatch(1);
|
||||||
latchC := TMycLatch.CreateLatch(1);
|
latchC := State.CreateLatch(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 := TMycLatch.CreateLatch(2);
|
latchA := State.CreateLatch(2);
|
||||||
latchB := TMycLatch.CreateLatch(1);
|
latchB := State.CreateLatch(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 := TMycLatch.CreateLatch(0); // Returns TMycLatch.Null which is set.
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(3);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latch := State.CreateLatch(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 := TMycLatch.CreateLatch(1);
|
latch := State.CreateLatch(1);
|
||||||
mockSubInitial := TMockSubscriber.Create;
|
mockSubInitial := TMockSubscriber.Create;
|
||||||
subscriptionInitial := latch.State.Subscribe(mockSubInitial);
|
subscriptionInitial := latch.State.Subscribe(mockSubInitial);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ uses
|
|||||||
System.Classes,
|
System.Classes,
|
||||||
System.SyncObjs,
|
System.SyncObjs,
|
||||||
Myc.Core.Tasks,
|
Myc.Core.Tasks,
|
||||||
Myc.Signals, // Uses TMycLatch.CreateLatch and TMycLatch.Null
|
Myc.Signals, Myc.Core.Signals,
|
||||||
Myc.Core.Atomic;
|
Myc.Core.Atomic;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|||||||
Reference in New Issue
Block a user