TsgcHTTP2ClientMethods › GetFuture

GetFuture Method

Runs an HTTP/2 GET on a background thread and returns a future that resolves to the response body.

Syntax

function GetFuture(const aURL: string): IsgcFuture<string>;

Parameters

NameTypeDescription
aURLconst stringAbsolute URL of the resource to retrieve.

Return Value

An IsgcFuture<string> that resolves to the response body. Call Await to block until the response arrives, ThenProc to consume the body in a continuation, OnError to handle failures, and Cancel to abort the request.

Remarks

GetFuture is the future-style counterpart of the synchronous Get: the request runs on a background thread and the method returns immediately, so the calling thread is never blocked. Unlike ConnectAsync and the other Async verbs, no event handler is required: the response is delivered through the returned future. Calling Cancel disconnects the client, so a request still waiting for its response is aborted instead of running to completion; an aborted or failed request rejects the future with an exception delivered to OnError (or re-raised by Await). Requires Delphi 2010 or later (and C++Builder 2010 or later); it is not available in the .NET edition.

Example

oClient.GetFuture('https://www.esegece.com')
  .ThenProc(procedure(const aBody: string)
    begin
      WriteLn(aBody);
    end)
  .OnError(procedure(E: Exception)
    begin
      WriteLn('Request failed: ' + E.Message);
    end);

Back to Methods