diff --git a/Src/Myc.Futures.pas b/Src/Myc.Futures.pas index 4334155..46410d2 100644 --- a/Src/Myc.Futures.pas +++ b/Src/Myc.Futures.pas @@ -40,6 +40,8 @@ type class function Construct( const Proc: TFunc ): TFuture; overload; static; class function Construct( const Gate: IMycState; const Proc: TFunc ): TFuture; overload; static; + class property Null: IMycFuture read FNull; + function Chain( const Proc: TFunc ): TFuture; function WaitFor: T; diff --git a/Src/Myc.Signals.pas b/Src/Myc.Signals.pas index 245bf17..ac14604 100644 --- a/Src/Myc.Signals.pas +++ b/Src/Myc.Signals.pas @@ -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;