List of all members
xxhr::sync Struct Reference

Helper object for the non-recommended good old synchronous way of thinking. More...

Detailed Description

Note that using this will not have great performance when you compile for the web browser platform. This will hang the browser UI until the request complete and some browsers (chrome) might not allocate execution time for the request to happen.

In xxhr there is nothing like a Synchronous API. While we think it's a bad idea to write anything synchronously, there are cases where it makes sense and it might be needed.

The issue with code which waits on IO is that they are non-welcome in the Web Browser, in new Windows apps or mobile platforms as they block the user from performing anything else until the operation complete.

Network operations are full of latency, therefore it is a pretty bad idea to read this example and to use it in your code. Because basically you can block your app forever (you might use an xxhr::Timeout to mitigate it, but the user isn't as patient as network operations are slow).

But if really it's your last resort, then you can simply use the xxhr::sync helper as follow :

xxhr::sync sync_;
GET("http://httpbin.org/post"s, on_response = sync_);
// blocks until response arrives
auto response = sync_();
std::cout << "Finally we got the reply : " << response.status_code << " and content : " << response.text << std::endl;

The documentation for this struct was generated from the following file:
xxhr::on_response
constexpr make_handler_t< on_response_ > on_response
Continuation callback ( i.e. signature : void callback(xxhr::Response)) for the asynchronous HTTP ope...
Definition: handler.hpp:39
xxhr::sync
Helper object for the non-recommended good old synchronous way of thinking.
Definition: sync.hpp:21
xxhr::GET
void GET(Ts &&... ts)
HTTP GET Request.
Definition: api.hpp:41