-
Notifications
You must be signed in to change notification settings - Fork 1
feat(components): only publish predicates on value change #123
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
Conversation
bpapaspyros
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c14a872 to
270836d
Compare
| TYPED_TEST(ComponentInterfaceTest, AddTrigger) { | ||
| EXPECT_NO_THROW(this->component_->add_trigger("trigger")); | ||
| ASSERT_FALSE(this->component_->triggers_.find("trigger") == this->component_->triggers_.end()); | ||
| EXPECT_FALSE(this->component_->triggers_.at("trigger")); | ||
| EXPECT_FALSE(this->component_->get_predicate("trigger")); | ||
| ASSERT_FALSE( | ||
| std::find(this->component_->triggers_.cbegin(), this->component_->triggers_.cend(), "trigger") | ||
| == this->component_->triggers_.cend()); | ||
| EXPECT_NO_THROW(this->component_->trigger("trigger")); | ||
| // When reading, the trigger will be true only once | ||
| this->component_->triggers_.at("trigger") = true; | ||
| EXPECT_TRUE(this->component_->triggers_.at("trigger")); | ||
| EXPECT_TRUE(this->component_->get_predicate("trigger")); | ||
| // After the predicate function was evaluated once, the trigger is back to false | ||
| EXPECT_FALSE(this->component_->triggers_.at("trigger")); | ||
| EXPECT_FALSE(this->component_->get_predicate("trigger")); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see how the triggering still works. Triggers are never added to the actual predicates_ map, are just published as true on trigger(), but I don't see where or how it would be published as false after being triggered. We normally waiting a step to put the trigger back down to false, but maybe you can just try
publish_predicate(trigger_name, true);
publish_predicate(trigger_name, false);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I did make this too easy. See my most recent commit. I believe that with
this->set_predicate(trigger_name, true);
this->predicates_.at(trigger_name).set_predicate([]() { return false; });
It will work because the first line changes the predicate value and fires it immediately and then the second step changes the internal predicate value back to false again such that the next time we check all predicate values, it is a falling edge.
270836d to
9b9ba32
Compare
eeberhard
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
Co-authored-by: Enrico Eberhard <32450951+eeberhard@users.noreply.github.com>
Description
This PR solves the issue by implementing option 3 of the parent issue. Review by commit (there was an intermediate commit just for formatting).
Review guidelines
Estimated Time of Review: 15 minutes
Checklist before merging: