Skip to content

fix: subscriber callback not removed #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/event_manager/src/event_manager.cpp
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@ bool EventManager::remove_subscriber(const std::string &topic, const std::string
{
std::lock_guard<std::recursive_mutex> lk(events_mutex_);
if (!events_.subscribers.contains(topic)) {
logger_.warn("Cannot remove subscriber, there are no subscribers for topic '{}'", topic);
// there is no publisher for this topic
return false;
}
@@ -128,6 +129,8 @@ bool EventManager::remove_subscriber(const std::string &topic, const std::string
auto elem = std::find(std::begin(topic_subscribers), std::end(topic_subscribers), component);
bool exists = elem != std::end(topic_subscribers);
if (!exists) {
logger_.warn("Cannot remove subscriber, '{}' is not registered as a subscriber for topic '{}'",
component, topic);
// component is not registered as a subscriber, so return false
return false;
}
@@ -138,7 +141,7 @@ bool EventManager::remove_subscriber(const std::string &topic, const std::string
// remove from `subscriber_callbacks_`
{
std::lock_guard<std::recursive_mutex> lk(callbacks_mutex_);
auto callbacks = subscriber_callbacks_[topic];
auto& callbacks = subscriber_callbacks_[topic];

auto is_component = [&component](std::pair<std::string, event_callback_fn> &e) {
return std::get<0>(e) == component;