Concurrent data processing
This commit is contained in:
+11
-19
@@ -79,7 +79,7 @@ type
|
||||
class operator Implicit(const A: TState): IState; overload;
|
||||
|
||||
class function All(const States: TArray<TState>): TState; static;
|
||||
class function Any(const States: TArray<TState>): TState; static;
|
||||
class function Any(const States: TArray<TState>; Count: Integer = 1): TState; static;
|
||||
|
||||
class property Null: IState read FNull;
|
||||
|
||||
@@ -138,6 +138,7 @@ type
|
||||
strict private
|
||||
class var
|
||||
FNull: ILatch;
|
||||
[volatile]
|
||||
FQueueLock: Integer;
|
||||
class constructor ClassCreate;
|
||||
|
||||
@@ -243,32 +244,23 @@ begin
|
||||
end;
|
||||
|
||||
class function TState.All(const States: TArray<TState>): TState;
|
||||
begin
|
||||
Result := Any(States, Length(States));
|
||||
end;
|
||||
|
||||
class function TState.Any(const States: TArray<TState>; Count: Integer = 1): TState;
|
||||
var
|
||||
Latch: TLatch.ILatch;
|
||||
begin
|
||||
Latch := TLatch.CreateLatch(Length(States));
|
||||
if (States = nil) or (Count <= 0) then
|
||||
exit(TState.Null);
|
||||
|
||||
Latch := TLatch.CreateLatch(Count);
|
||||
for var state in States do
|
||||
state.Signal.Subscribe(Latch);
|
||||
Result := Latch.State;
|
||||
end;
|
||||
|
||||
class function TState.Any(const States: TArray<TState>): TState;
|
||||
var
|
||||
Latch: TLatch.ILatch;
|
||||
begin
|
||||
if Length(States) = 0 then
|
||||
begin
|
||||
Result := TState.Null;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Latch := TLatch.CreateLatch(1);
|
||||
for var state in States do
|
||||
state.Signal.Subscribe(Latch);
|
||||
Result := Latch.State;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TState.GetSignal: TSignal;
|
||||
begin
|
||||
Result := FState.Signal;
|
||||
|
||||
Reference in New Issue
Block a user