From 19ee1fa8376c73c960c7853eb0e253d645219b7c Mon Sep 17 00:00:00 2001 From: Benjamin Roland Buch Date: Mon, 9 Apr 2018 16:34:21 +0200 Subject: [PATCH] fixed bugs --- src/http_server.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/http_server.cpp b/src/http_server.cpp index e5e66b7..b480671 100644 --- a/src/http_server.cpp +++ b/src/http_server.cpp @@ -179,6 +179,10 @@ namespace disposer_module::http_server_component{ , interval_(component_("min_interval_in_ms"_param)) {} ~running_chains(){ + wait_on_last_async(); + } + + void wait_on_last_async(){ // As long as async calls are pending while(async_calls_ > 0){ // Request the server to run a handler async @@ -190,6 +194,7 @@ namespace disposer_module::http_server_component{ } } + void add( std::string const& chain, std::optional< std::size_t > exec_count = {} @@ -236,6 +241,8 @@ namespace disposer_module::http_server_component{ return; } + if(chains_.empty()) return; + timer_.expires_after(interval_); timer_.async_wait( [this, lock = webservice::async_lock(async_calls_)]( @@ -271,9 +278,15 @@ namespace disposer_module::http_server_component{ void on_shutdown()noexcept final{ - std::lock_guard lock(mutex_); + std::unique_lock lock(mutex_); shutdown_ = true; + lock.unlock(); + timer_.cancel(); + + wait_on_last_async(); + + lock.lock(); for(auto& pair: chains_){ lockless_erase(pair.first); }