Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/rpp/rpp/subjects/behavior_subject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ namespace rpp::subjects::details
return m_state;
}

Type get_value() const
{
return *m_state.lock()->get_value();
}


private:
disposable_wrapper_impl<behavior_state> m_state;
};
Expand Down
4 changes: 4 additions & 0 deletions src/tests/rpp/test_subjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ TEMPLATE_TEST_CASE("replay subject multicasts values and replay", "", rpp::subje
const auto mock_1 = mock_observer_strategy<int>{};
const auto subj = TestType{10};

CHECK(subj.get_value() == 10);

SECTION("subscribe to subject with default")
{
subj.get_observable().subscribe(mock_1);
Expand All @@ -451,6 +453,7 @@ TEMPLATE_TEST_CASE("replay subject multicasts values and replay", "", rpp::subje
const auto mock_2 = mock_observer_strategy<int>{};

subj.get_observer().on_next(5);
CHECK(subj.get_value() == 5);

CHECK(mock_1.get_received_values() == std::vector<int>{10, 5});
CHECK(mock_2.get_received_values() == std::vector<int>{});
Expand All @@ -463,6 +466,7 @@ TEMPLATE_TEST_CASE("replay subject multicasts values and replay", "", rpp::subje
{
const auto mock_3 = mock_observer_strategy<int>{};
subj.get_observer().on_next(1);
CHECK(subj.get_value() == 1);

CHECK(mock_1.get_received_values() == std::vector<int>{10, 5, 1});
CHECK(mock_2.get_received_values() == std::vector<int>{5, 1});
Expand Down