diff --git a/include/rtc/include.hpp b/include/rtc/include.hpp index b0489d4..f4c35b8 100644 --- a/include/rtc/include.hpp +++ b/include/rtc/include.hpp @@ -60,15 +60,17 @@ public: return *this; } - void operator()(P... args) { + void operator()(P... args) const { std::lock_guard lock(mutex); if (callback) callback(args...); } + operator bool() const { return callback ? true : false; } + private: std::function callback; - std::recursive_mutex mutex; + mutable std::recursive_mutex mutex; }; } diff --git a/src/channel.cpp b/src/channel.cpp index 214e081..c3cc09b 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -67,7 +67,7 @@ void Channel::triggerAvailable(size_t available) { if (available == 1) mAvailableCallback(); - while (available--) { + while (mMessageCallback && available--) { auto message = receive(); if (!message) break;