Skip to content

Commit

Permalink
feat: Add bool return trype to process event (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzenker authored Nov 27, 2021
1 parent fe5461d commit fbea52e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions include/hsm/details/sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ template <class RootState, class... OptionalParameters> class sm {
update_current_regions();
}

template <class Event> auto process_event(Event&& event)
template <class Event> auto process_event(Event&& event) -> bool
{
static_assert(
bh::contains(
Expand All @@ -87,10 +87,11 @@ template <class RootState, class... OptionalParameters> class sm {

if (!process_event_internal(event)) {
call_unexpected_event_handler(event);
return;
return false;
}

process_deferred_events();
return true;
}

template <class State> auto is(State state) -> bool
Expand Down
6 changes: 3 additions & 3 deletions test/integration/unexpected_event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ class UnexpectedEventHandler : public Test {
TEST_F(UnexpectedEventHandler, should_call_unexpected_event_handler)
{
auto event = e2 {};
sm.process_event(event);
ASSERT_FALSE(sm.process_event(event));

ASSERT_TRUE(event.called);
}

TEST_F(UnexpectedEventHandler, should_not_call_unexpected_event_handler_when_guard_fails)
{

sm.process_event(e3 {});
ASSERT_TRUE(sm.process_event(e3 {}));

auto event = e2 {};
sm.process_event(event);
ASSERT_TRUE(sm.process_event(event));

ASSERT_FALSE(event.called);
}

0 comments on commit fbea52e

Please sign in to comment.