Do not receive messages in onMessage is not set

This commit is contained in:
Paul-Louis Ageneau
2019-12-04 12:16:39 +01:00
parent a1df562785
commit 4029a9bb4a
2 changed files with 5 additions and 3 deletions

View File

@ -60,15 +60,17 @@ public:
return *this; return *this;
} }
void operator()(P... args) { void operator()(P... args) const {
std::lock_guard<std::recursive_mutex> lock(mutex); std::lock_guard<std::recursive_mutex> lock(mutex);
if (callback) if (callback)
callback(args...); callback(args...);
} }
operator bool() const { return callback ? true : false; }
private: private:
std::function<void(P...)> callback; std::function<void(P...)> callback;
std::recursive_mutex mutex; mutable std::recursive_mutex mutex;
}; };
} }

View File

@ -67,7 +67,7 @@ void Channel::triggerAvailable(size_t available) {
if (available == 1) if (available == 1)
mAvailableCallback(); mAvailableCallback();
while (available--) { while (mMessageCallback && available--) {
auto message = receive(); auto message = receive();
if (!message) if (!message)
break; break;