forked from byterazor/EventManager
ADD: method to wait for new event with timeout
This commit is contained in:
parent
8f78070770
commit
789ce929a4
@ -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
|
||||
|
@ -11,6 +11,9 @@
|
||||
#include <EventManager/Participant.hpp>
|
||||
#include <EventManager/Manager.hpp>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
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<std::mutex> lock(mutexEventQueue_);
|
||||
newEventInQueue_.wait_for(lock,timeoutMS*1ms);
|
||||
isQueueLocked_=true;
|
||||
}
|
||||
|
||||
|
||||
void EventManager::Participant::_enableScheduling()
|
||||
{
|
||||
if (manager_ == nullptr)
|
||||
|
Loading…
Reference in New Issue
Block a user