fabriciocolombo / delphi-rest-client-api

A Delphi REST client API to consume REST services written in any programming language.
Apache License 2.0
380 stars 182 forks source link

Implements Async requests for WinHTTP #61

Closed fabioxgn closed 8 years ago

fabioxgn commented 8 years ago

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:

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();
fabriciocolombo commented 8 years ago

Great pull request, thank you.