Fixed check for pending tasks Goal was to move ready tasks to the end of array. Existing coded did opposite. Also movable types can be invalid in the second part of the array after applying remove_if. BUG:24204632 Change-Id: I9be84fa8f536337a265c1e24cc75036c7fca8dbb Reviewed-on: https://weave-review.googlesource.com/1500 Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/examples/provider/curl_http_client.cc b/examples/provider/curl_http_client.cc index 3dcfe3d..32aa4af 100644 --- a/examples/provider/curl_http_client.cc +++ b/examples/provider/curl_http_client.cc
@@ -8,9 +8,10 @@ #include <thread> #include <base/bind.h> +#include <base/logging.h> #include <curl/curl.h> -#include <weave/provider/task_runner.h> #include <weave/enum_to_string.h> +#include <weave/provider/task_runner.h> namespace weave { namespace examples { @@ -130,15 +131,16 @@ } void CurlHttpClient::CheckTasks() { - VLOG(3) << "CurlHttpClient::CheckTasks, size=" << pending_tasks_.size(); + VLOG(4) << "CurlHttpClient::CheckTasks, size=" << pending_tasks_.size(); auto ready_begin = - std::remove_if(pending_tasks_.begin(), pending_tasks_.end(), + std::partition(pending_tasks_.begin(), pending_tasks_.end(), [](const decltype(pending_tasks_)::value_type& value) { return value.first.wait_for(std::chrono::seconds(0)) != std::future_status::ready; }); for (auto it = ready_begin; it != pending_tasks_.end(); ++it) { + CHECK(it->first.valid()); auto result = it->first.get(); VLOG(2) << "CurlHttpClient::CheckTasks done"; task_runner_->PostDelayedTask(