Pike v8.1 release 6

Module Protocols.HTTP.Promise

Description

This HTTP client module utilises the Concurrent.Promise and Concurrent.Future classes and only does asynchronous calls.

Example
Protocols.HTTP.Promise.Arguments a1, a2;

a1 = Protocols.HTTP.Promise.Arguments(([
  "extra_args" : ({ "Extra arg for Roxen request" }),
  "headers"    : ([ "User-Agent" : "My Special HTTP Client" ])
]));

a2 = Protocols.HTTP.Promise.Arguments(([
  "variables" : ([ "q" : "Pike programming language" ]),
  "maxtime"   : 10
]));

Concurrent.Future q1 = Protocols.HTTP.Promise.get_url("http://www.roxen.com", a1);
Concurrent.Future q2 = Protocols.HTTP.Promise.get_url("http://www.google.com", a2);

array(Concurrent.Future) all = ({ q1, q2 });

/*
  To get a callback for each of the requests
*/

all->on_success(lambda (Protocols.HTTP.Promise.Success ok_resp) {
  werror("Got successful response for %O\n", ok_resp->host);
});
all->on_failure(lambda (Protocols.HTTP.Promise.Failure failed_resp) {
  werror("Request for %O failed!\n", failed_resp->host);
});

/*
  To get a callback when all of the requests are done. In this case
  on_failure will be called if any of the request fails.
*/

Concurrent.Future all2 = Concurrent.results(all);

all2->on_success(lambda (array(Protocols.HTTP.Promise.Success) ok_resp) {
  werror("All request were successful: %O\n", ok_resp);
});
all->on_failure(lambda (Protocols.HTTP.Promise.Failure failed_resp) {
  werror("The request to %O failed.\n", failed_resp->host);
});