TLatch extended

This commit is contained in:
Michael Schimmel
2025-06-04 01:54:20 +02:00
parent f438c91dbd
commit f033ef2c0f
2 changed files with 62 additions and 2 deletions
+2
View File
@@ -40,6 +40,8 @@ type
class function Construct( const Proc: TFunc<T> ): TFuture<T>; overload; static;
class function Construct( const Gate: IMycState; const Proc: TFunc<T> ): TFuture<T>; overload; static;
class property Null: IMycFuture<T> read FNull;
function Chain<S>( const Proc: TFunc<T, S> ): TFuture<S>;
function WaitFor: T;
+60 -2
View File
@@ -74,9 +74,25 @@ type
class var
FNull: IMycLatch;
class constructor ClassCreate;
private
FLatch: IMycLatch;
function GetState: TState; inline;
public
class function Construct( Count: Integer ): IMycLatch; static;
constructor Create(const ALatch: IMycLatch);
class operator Initialize(out Dest: TLatch);
class operator Implicit(const A: IMycLatch): TLatch; overload;
class operator Implicit(const A: TLatch): IMycLatch; overload;
class function Construct(Count: Integer): TLatch; static;
class function Enqueue(var Gate: TLatch; Count: Integer=1): TState; static;
class property Null: IMycLatch read FNull;
function Notify: Boolean; inline;
property State: TState read GetState;
end;
// IMycDirty represents a resettable flag, typically indicating if a State is "dirty" (requiring attention) or "clean".
@@ -203,7 +219,16 @@ begin
FNull := TMycNullLatch.Create; // Calls the instance constructor
end;
class function TLatch.Construct( Count: Integer ): IMycLatch;
{ TLatch }
constructor TLatch.Create(const ALatch: IMycLatch);
begin
FLatch := ALatch;
if not Assigned( FLatch ) then
FLatch := FNull;
end;
class function TLatch.Construct(Count: Integer): TLatch;
begin
if Count > 0 then
Result := TMycLatch.Create( Count )
@@ -211,6 +236,39 @@ begin
Result := FNull;
end;
class function TLatch.Enqueue(var Gate: TLatch; Count: Integer=1): TState;
begin
var gateState := Gate.State;
Gate := TMycLatch.Create( Count );
gateState.Subscribe( Gate );
exit( Gate.State );
end;
function TLatch.GetState: TState;
begin
Result := FLatch.State;
end;
function TLatch.Notify: Boolean;
begin
Result := FLatch.Notify;
end;
class operator TLatch.Implicit(const A: IMycLatch): TLatch;
begin
Result.Create( A );
end;
class operator TLatch.Implicit(const A: TLatch): IMycLatch;
begin
Result := A.FLatch;
end;
class operator TLatch.Initialize(out Dest: TLatch);
begin
Dest.FLatch := FNull;
end;
{ TDirty }
class constructor TDirty.ClassCreate;