TLatch extended
This commit is contained in:
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user