diff --git a/include/EventManager/Participant.hpp b/include/EventManager/Participant.hpp index 56329b6..8a3c76f 100644 --- a/include/EventManager/Participant.hpp +++ b/include/EventManager/Participant.hpp @@ -100,6 +100,10 @@ */ void _waitForEvent(); + /** + * @brief wait for a new event with timeout + */ + void _waitForEvent(std::uint32_t timeoutMS); /** * @brief This method subscribes the participant to an event type diff --git a/src/EventManager/Participant.cpp b/src/EventManager/Participant.cpp index f511e0a..35c2357 100644 --- a/src/EventManager/Participant.cpp +++ b/src/EventManager/Participant.cpp @@ -11,6 +11,9 @@ #include #include #include + #include + using namespace std::chrono_literals; + EventManager::Participant::Participant() : manager_(nullptr), isScheduledByManager_(false), isQueueLocked_(false) @@ -91,6 +94,14 @@ void EventManager::Participant::_waitForEvent() isQueueLocked_=true; } +void EventManager::Participant::_waitForEvent(std::uint32_t timeoutMS) +{ + std::unique_lock lock(mutexEventQueue_); + newEventInQueue_.wait_for(lock,timeoutMS*1ms); + isQueueLocked_=true; +} + + void EventManager::Participant::_enableScheduling() { if (manager_ == nullptr)