diff --git a/include/Listener.h b/include/Listener.h index ab0ebcf6d6..e7ef825d04 100644 --- a/include/Listener.h +++ b/include/Listener.h @@ -162,19 +162,23 @@ protected: { end = false; - std::unique_lock ul(lock); - while (true) { - cond.wait(ul, [&]{return (end || !pending.empty());}); + std::function fn; - if (end) { - break; - } + std::unique_lock ul(lock); - auto fn = pending.front(); - pending.pop(); + cond.wait(ul, [&]{return (end || !pending.empty());}); + + if (end) + { + break; + } + + fn = pending.front(); + pending.pop(); + } fn(); }