upd: change event bus
- Make `.subscribeOnce` return listener id - Make `.cancel` and `.isCanceled` methods in `MscEvent` implemented
This commit is contained in:
@@ -18,10 +18,19 @@ public:
|
|||||||
virtual std::string getName() const = 0;
|
virtual std::string getName() const = 0;
|
||||||
|
|
||||||
/// @brief Is current event is canceled
|
/// @brief Is current event is canceled
|
||||||
virtual bool isCanceled() const = 0;
|
bool isCanceled() const
|
||||||
|
{
|
||||||
|
return canceled;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Cancel current event
|
/// @brief Cancel current event
|
||||||
virtual void cancel() = 0;
|
void cancel()
|
||||||
|
{
|
||||||
|
canceled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool canceled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Engine event bus
|
/// @brief Engine event bus
|
||||||
@@ -47,7 +56,7 @@ public:
|
|||||||
/// @brief Subscribe to specified event and execute once on publish
|
/// @brief Subscribe to specified event and execute once on publish
|
||||||
/// @param name event name
|
/// @param name event name
|
||||||
/// @param listener event handler
|
/// @param listener event handler
|
||||||
void subscribeOnce(const std::string &name, Listener listener);
|
SubscriptionId subscribeOnce(const std::string &name, Listener listener);
|
||||||
|
|
||||||
/// @brief Unsubscribe listener by its own id
|
/// @brief Unsubscribe listener by its own id
|
||||||
/// @param id subscription id
|
/// @param id subscription id
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ MscEventBus::SubscriptionId MscEventBus::subscribe(const std::string &name, List
|
|||||||
return _subscribe(name, std::move(listener), false);
|
return _subscribe(name, std::move(listener), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MscEventBus::subscribeOnce(const std::string &name, Listener listener)
|
MscEventBus::SubscriptionId MscEventBus::subscribeOnce(const std::string &name, Listener listener)
|
||||||
{
|
{
|
||||||
_subscribe(name, std::move(listener), true);
|
return _subscribe(name, std::move(listener), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MscEventBus::unsubscribe(SubscriptionId id)
|
bool MscEventBus::unsubscribe(SubscriptionId id)
|
||||||
|
|||||||
Reference in New Issue
Block a user