web_sevice: Replace std::launch::deferred with std::launch::async

In not every case, we were actually performing a get() on the result of the web_backend operation. Instead we waited for the function that got passed as parameter to be executed and would then perform a get() in it. With std::launch::deferred this would never happen, cause the passed function would never get executed.
This commit is contained in:
fearlessTobi 2018-09-02 17:50:19 +02:00
parent 978611e51e
commit 252014475b

View File

@ -117,7 +117,7 @@ std::future<Common::WebResult> PostJson(const std::string& url, const std::strin
if (url.empty() || !parsedUrl.IsValid()) {
LOG_ERROR(WebService, "URL is invalid");
return std::async(std::launch::deferred, [] {
return std::async(std::launch::async, [] {
return Common::WebResult{Common::WebResult::Code::InvalidURL, "URL is invalid"};
});
}
@ -128,7 +128,7 @@ std::future<Common::WebResult> PostJson(const std::string& url, const std::strin
const bool are_credentials_provided{!jwt.empty()};
if (!allow_anonymous && !are_credentials_provided) {
LOG_ERROR(WebService, "Credentials must be provided for authenticated requests");
return std::async(std::launch::deferred, [] {
return std::async(std::launch::async, [] {
return Common::WebResult{Common::WebResult::Code::CredentialsMissing,
"Credentials needed"};
});
@ -160,7 +160,7 @@ std::future<Common::WebResult> PostJson(const std::string& url, const std::strin
if (url.empty() || !parsedUrl.IsValid()) {
LOG_ERROR(WebService, "URL is invalid");
return std::async(std::launch::deferred, [] {
return std::async(std::launch::async, [] {
return Common::WebResult{Common::WebResult::Code::InvalidURL, ""};
});
}
@ -168,7 +168,7 @@ std::future<Common::WebResult> PostJson(const std::string& url, const std::strin
const bool are_credentials_provided{!token.empty() && !username.empty()};
if (!are_credentials_provided) {
LOG_ERROR(WebService, "Credentials must be provided for authenticated requests");
return std::async(std::launch::deferred, [] {
return std::async(std::launch::async, [] {
return Common::WebResult{Common::WebResult::Code::CredentialsMissing, ""};
});
}
@ -203,7 +203,7 @@ std::future<T> GetJson(std::function<T(const std::string&)> func, const std::str
if (url.empty() || !parsedUrl.IsValid()) {
LOG_ERROR(WebService, "URL is invalid");
return std::async(std::launch::deferred, [func{std::move(func)}]() { return func(""); });
return std::async(std::launch::async, [func{std::move(func)}]() { return func(""); });
}
const std::string jwt =
@ -212,7 +212,7 @@ std::future<T> GetJson(std::function<T(const std::string&)> func, const std::str
const bool are_credentials_provided{!jwt.empty()};
if (!allow_anonymous && !are_credentials_provided) {
LOG_ERROR(WebService, "Credentials must be provided for authenticated requests");
return std::async(std::launch::deferred, [func{std::move(func)}]() { return func(""); });
return std::async(std::launch::async, [func{std::move(func)}]() { return func(""); });
}
// Built request header