From 0dc624a3e6ec7883ff81746963efc5500ac587d8 Mon Sep 17 00:00:00 2001 From: Michael van der Werve Date: Wed, 7 Oct 2020 16:12:15 +0200 Subject: [PATCH] {auto} if there are no open messages, close channel directly --- src/throttle.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/throttle.cpp b/src/throttle.cpp index 052a252..d8d58a5 100644 --- a/src/throttle.cpp +++ b/src/throttle.cpp @@ -200,7 +200,15 @@ Deferred &Throttle::close() // create the deferred _close = std::make_shared(_implementation->usable()); - // return the deferred + // if there are open messages or there is a queue, they will still get acked and we will then forward it + if (_open.size() > 0 || !_queue.empty()) return *_close; + + // there are no open messages, we can close the channel directly. + _implementation->close() + .onSuccess([this]() { _close->reportSuccess(); }) + .onError([this](const char *message) { _close->reportError(message); }); + + // return the created deferred return *_close; }