AuraTrader Sample
This commit is contained in:
@@ -13,6 +13,8 @@ type
|
||||
protected
|
||||
function GetValue: T; virtual; abstract;
|
||||
function GetDone: TState; virtual; abstract;
|
||||
public
|
||||
procedure BeforeDestruction; override;
|
||||
end;
|
||||
|
||||
TMycNullFuture<T> = class(TMycFuture<T>)
|
||||
@@ -34,8 +36,27 @@ type
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
TMycFutureManaged<T> = class(TMycFuture<T>)
|
||||
private
|
||||
FFuture: TFuture<T>.IFuture;
|
||||
protected
|
||||
function GetValue: T; override;
|
||||
function GetDone: TState; override;
|
||||
public
|
||||
constructor Create(const AFuture: TFuture<T>.IFuture);
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TMycFuture<T> }
|
||||
|
||||
procedure TMycFuture<T>.BeforeDestruction;
|
||||
begin
|
||||
inherited;
|
||||
Assert(GetDone.IsSet, 'Trying to destroy an unfinished future');
|
||||
end;
|
||||
|
||||
{ TMycNullFuture<T> }
|
||||
|
||||
function TMycNullFuture<T>.GetDone: TState;
|
||||
@@ -79,8 +100,6 @@ end;
|
||||
|
||||
destructor TMycGateFuncFuture<T>.Destroy;
|
||||
begin
|
||||
Assert(FDone.State.IsSet, 'Future not done');
|
||||
|
||||
FInit.Unsubscribe;
|
||||
inherited Destroy;
|
||||
end;
|
||||
@@ -96,4 +115,34 @@ begin
|
||||
Result := FResult;
|
||||
end;
|
||||
|
||||
{ TMycFutureManaged<T> }
|
||||
|
||||
constructor TMycFutureManaged<T>.Create(const AFuture: TFuture<T>.IFuture);
|
||||
begin
|
||||
inherited Create;
|
||||
FFuture := AFuture;
|
||||
end;
|
||||
|
||||
destructor TMycFutureManaged<T>.Destroy;
|
||||
begin
|
||||
if GetTypeKind(T) = tkClass then
|
||||
begin
|
||||
var val := GetValue;
|
||||
var obj := TObject(PPointer(@val)^);
|
||||
if obj <> nil then
|
||||
obj.Free;
|
||||
end;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function TMycFutureManaged<T>.GetDone: TState;
|
||||
begin
|
||||
Result := FFuture.Done;
|
||||
end;
|
||||
|
||||
function TMycFutureManaged<T>.GetValue: T;
|
||||
begin
|
||||
Result := FFuture.Value;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user