This allows a long running request to be cancelled and also to update the UI without using a thread.
I'm making requests to a longpoll server and the request can take up to 60 seconds and if I close the application it waits until the request is finished so it might take up to 60 seconds to close.
Some details about the implementation:
When the request is cancelled an EAbort exception is raised.
There is a new OnAsyncRequestProcess event in TRestClient that is called every second (min wait time for WinHTTP)
When you free the TRestClient, if Async is True and there is a running request it is cancelled before freeing the connection
Here's an exemple of use:
RestClient.OnAsyncRequestProcess :=
procedure(var Cancel: Boolean)
begin
Cancel := True; // Set cancel to true to abort the request
end;
// This will raise an EAbort if the request is canceled
RestClient.Resource(CONTEXT_PATH + 'async')
.Accept('text/plain')
.Async
.GET();
This allows a long running request to be cancelled and also to update the UI without using a thread.
I'm making requests to a longpoll server and the request can take up to 60 seconds and if I close the application it waits until the request is finished so it might take up to 60 seconds to close.
Some details about the implementation:
EAbort
exception is raised.OnAsyncRequestProcess
event inTRestClient
that is called every second (min wait time for WinHTTP)Here's an exemple of use: