Skip to content

Commit

Permalink
🚧 Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
p-samuel committed Mar 25, 2023
1 parent d9824b6 commit 2fdd718
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/Notify.Api.Indy.pas
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ destructor TSSEThread.Destroy;
procedure TSSEThread.DoOnWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
var
LEventString: UTF8String;
LString: UTF8String;
LString: String;
{$IFDEF VER310}
LStrings: TStringDynArray;
{$ELSE}
Expand All @@ -360,7 +360,7 @@ procedure TSSEThread.DoOnWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount
LStrings := SplitString(UTF8ToString(LEventString), #$A);

for LString in LStrings do
NxHorizon.Instance.Post<TNotifySubscriptionEvent>(UTF8ToString(LString));
NxHorizon.Instance.Post<TNotifySubscriptionEvent>(Utf8String(LString));

end;

Expand Down
33 changes: 13 additions & 20 deletions src/Notify.Api.NetHTTP.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TSSEThread = class(TThread)
FEventStream: TMemoryStream;
FResponse: TNotifyApiResponse;
FHeaders: TNetHeaders;
procedure NetHTTPRequestReceiveData(const Sender: TObject; AContentLength, AReadCount: Int64; var AAbort: Boolean);
procedure ReceiveData(const Sender: TObject; AContentLength, AReadCount: Int64; var AAbort: Boolean);
public
constructor Create(const AUrl: String; const AHeaders: TNetHeaders; var ANetHTTPRequest: TNetHTTPRequest; var AResponse: TNotifyApiResponse);
procedure Execute; override;
Expand Down Expand Up @@ -329,21 +329,19 @@ function TNotifyApiNetHTTP.Response: TNotifyApiResponse;
{ TSSEThread }

procedure TSSEThread.AbortStream;
var
LAbort: Boolean;
begin
LAbort := True;
FNetHTTPResquest.Cancel;

end;

constructor TSSEThread.Create(const AUrl: String; const AHeaders: TNetHeaders;
var ANetHTTPRequest: TNetHTTPRequest; var AResponse: TNotifyApiResponse);
begin
inherited Create(True);
FreeOnTerminate := False;
FreeOnTerminate := True;
FUrl := AUrl;
FNetHTTPResquest := ANetHTTPRequest;
FResponse := AResponse;
FHeaders := AHeaders;
end;

destructor TSSEThread.Destroy;
Expand All @@ -354,24 +352,19 @@ destructor TSSEThread.Destroy;
procedure TSSEThread.Execute;
begin
inherited;
FEventStream := TMemoryStream.Create;
try
FEventStream := TMemoryStream.Create;
FNetHTTPResquest.OnReceiveData := NetHTTPRequestReceiveData;
FNetHTTPResquest.OnReceiveData := ReceiveData;
FNetHTTPResquest.Accept := 'text/event-stream';
while not Terminated do
begin
try
try
FNetHTTPResquest.Get(FUrl, FEventStream, FHeaders);
finally
Terminate;
end;
FNetHTTPResquest.Get(FUrl, FEventStream, FHeaders);
Terminate;
Break;
except
on E: Exception do
begin
Terminate;
Exit;
end;
Terminate;
Break;
end;
end;

Expand All @@ -380,7 +373,7 @@ procedure TSSEThread.Execute;
end;
end;

procedure TSSEThread.NetHTTPRequestReceiveData(const Sender: TObject;
procedure TSSEThread.ReceiveData(const Sender: TObject;
AContentLength, AReadCount: Int64; var AAbort: Boolean);
var
LEventString: UTF8String;
Expand All @@ -389,7 +382,7 @@ procedure TSSEThread.NetHTTPRequestReceiveData(const Sender: TObject;
begin

if Terminated then
FNetHTTPResquest.Free;
Exit;

SetString(LEventString, PAnsiChar(FEventStream.Memory), FEventStream.Size);

Expand Down
12 changes: 4 additions & 8 deletions src/Notify.Core.pas
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ function TNotifyCore.Subscribe: INotifyCore;
.Instance
.Subscribe<TNotifySubscriptionEvent>(MainSync, SubscriptionEvent);

FApi


FApi := TNotifyCoreFacade.New.Api
.Config(FConfig)
.ClearURLParameters;

Expand Down Expand Up @@ -496,14 +498,8 @@ function TNotifyCore.Topic(const AValue: String): INotifyCore;
function TNotifyCore.Unsubscribe: INotifyCore;
begin
Result := Self;

{$IFDEF CONSOLE}
// raise Exception.Create('Unsubscribe for console application is not supported. Kill the process.');
{$ENDIF}

UnsubscribeEventBus;
FApi.AbortStream;

FApi := nil;
end;

procedure TNotifyCore.UnsubscribeEventBus;
Expand Down

0 comments on commit 2fdd718

Please sign in to comment.