0

I have started working with 'cpp rest sdk'. The key point I understood it that all requests and response are asynchronous using the means of PPL. This is fine to boost scalability and performance of the application.

The question I have is weather is any way to request and wait for a response in a 'synchronous' fashion.

I found the following web page which seems to work fine and it claims to make call in synchronous way. Is it so?

Does a call to task::get() guarantees that the function returns when the response is ready to be read?

Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
  • Can you please provide code example of what you tried? Also, for links it's best to have their core content copied here, because links tend to die. Thank you :-) – Fabien Jul 18 '17 at 20:58

1 Answers1

1

The major idea of asynchronous programming is to chain all parts you want to have executed sequentially. If you want the program to wait until the sequence is finished, you can end the chain with .wait()

client.request(web::http::methods::GET, U("/foo.html"))
      .then(/*some lambda*/)
      .then(/*some lambda*/)   //and so on
      .wait();                 //stop here until the chain is executed

Similarly, you can also use get() which also calls wait() but further returns the result of the task.

davidhigh
  • 14,652
  • 2
  • 44
  • 75