.then() / .wait() on task tree?

Jun 22, 2015 at 4:35 PM
I have a function pplx::task<void> Authorize() that calls a REST API, then parses the response afterwards when the extract_json() task completes.

If I return the first client.request() task from inside Authorize(), then call Authorize().then([]{}); the lambda will be executed before the result is processed by the inner most task in Authorize().

Is there a pattern I can use to execute my lambda only when all the nested tasks are complete? How should cases like this be handled?
Jun 22, 2015 at 7:20 PM
Hi DesktopMan,

Without seeing your code it is a little difficult to describe, but you always can choose to return the last task in your processing chain. I.e. the task that executes after calling extract_json(). Just to make sure everything is clear the task returned from http_client::request(...) is completed once the HTTP headers have arrived, the response body may or may not have completely arrived yet. If you want to wait for the entire HTTP response body to arrive as well you need to wait until the task returned from either http_response::content_ready() or one of the http_response::extract_* methods is completed.