Skip to content

Conversation

@domire8
Copy link
Member

@domire8 domire8 commented Jun 27, 2024

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:

  • Confirm that the relevant changelog(s) are up-to-date in case of any user-facing changes

@domire8 domire8 linked an issue Jun 27, 2024 that may be closed by this pull request
Copy link

@bpapaspyros bpapaspyros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I was in favour of option 3 from #122. I am approving, but I would also like to see feedback on #122 from the other reviewers before it's merged.

@domire8 domire8 force-pushed the feat/publish-pred-on-change branch 2 times, most recently from c14a872 to 270836d Compare July 1, 2024 06:56
Comment on lines 314 to 321
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"));
}
Copy link
Member

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);

Copy link
Member Author

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.

@domire8 domire8 force-pushed the feat/publish-pred-on-change branch from 270836d to 9b9ba32 Compare July 4, 2024 13:17
Copy link
Member

@eeberhard eeberhard left a 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>
@domire8 domire8 merged commit 9fe2c66 into breaking Jul 4, 2024
@domire8 domire8 deleted the feat/publish-pred-on-change branch July 4, 2024 14:51
@github-actions github-actions bot locked and limited conversation to collaborators Jul 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publish predicates only on value change

3 participants