From 52cc951188d1a5af28f0d181cd406bd1d2f61c80 Mon Sep 17 00:00:00 2001 From: bjanjic <50588225+bjanjic@users.noreply.github.com> Date: Mon, 3 Jun 2019 14:12:08 +0200 Subject: [PATCH 1/2] Added new method in Crow class: - Added method wait_pending_jobs to support waiting of pending posts --- include/crow/crow.hpp | 6 ++++++ src/crow.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/include/crow/crow.hpp b/include/crow/crow.hpp index 006e4eb..de1c74b 100644 --- a/include/crow/crow.hpp +++ b/include/crow/crow.hpp @@ -227,6 +227,12 @@ class crow */ void clear_context(); + /*! + * @brief waits for all pending posts/jobs to complete + * + */ + void wait_pending_jobs() const; + /*! * @} */ diff --git a/src/crow.cpp b/src/crow.cpp index 9a10180..357ebb4 100644 --- a/src/crow.cpp +++ b/src/crow.cpp @@ -342,6 +342,13 @@ void crow::clear_context() } } +void crow::wait_pending_jobs() const { + std::lock_guard lock_jobs(m_jobs_mutex); + + for (auto it = m_jobs.begin(); it != m_jobs.end(); ++it) + it->wait(); +} + std::string crow::post(json payload) const { curl_wrapper curl; From fe84cf83ac03828272ebddb75d1692e931dc25ca Mon Sep 17 00:00:00 2001 From: bjanjic <50588225+bjanjic@users.noreply.github.com> Date: Mon, 3 Jun 2019 15:18:55 +0200 Subject: [PATCH 2/2] Code style changes... --- src/crow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crow.cpp b/src/crow.cpp index 357ebb4..b6942be 100644 --- a/src/crow.cpp +++ b/src/crow.cpp @@ -345,8 +345,9 @@ void crow::clear_context() void crow::wait_pending_jobs() const { std::lock_guard lock_jobs(m_jobs_mutex); - for (auto it = m_jobs.begin(); it != m_jobs.end(); ++it) + for (auto it = m_jobs.begin(); it != m_jobs.end(); ++it) { it->wait(); + } } std::string crow::post(json payload) const