diff --git a/src/rpp/rpp/subjects/behavior_subject.hpp b/src/rpp/rpp/subjects/behavior_subject.hpp index 110f82b9b..261548c88 100644 --- a/src/rpp/rpp/subjects/behavior_subject.hpp +++ b/src/rpp/rpp/subjects/behavior_subject.hpp @@ -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 m_state; }; diff --git a/src/tests/rpp/test_subjects.cpp b/src/tests/rpp/test_subjects.cpp index 39100a4c1..a16fac72a 100644 --- a/src/tests/rpp/test_subjects.cpp +++ b/src/tests/rpp/test_subjects.cpp @@ -441,6 +441,8 @@ TEMPLATE_TEST_CASE("replay subject multicasts values and replay", "", rpp::subje const auto mock_1 = mock_observer_strategy{}; const auto subj = TestType{10}; + CHECK(subj.get_value() == 10); + SECTION("subscribe to subject with default") { subj.get_observable().subscribe(mock_1); @@ -451,6 +453,7 @@ TEMPLATE_TEST_CASE("replay subject multicasts values and replay", "", rpp::subje const auto mock_2 = mock_observer_strategy{}; subj.get_observer().on_next(5); + CHECK(subj.get_value() == 5); CHECK(mock_1.get_received_values() == std::vector{10, 5}); CHECK(mock_2.get_received_values() == std::vector{}); @@ -463,6 +466,7 @@ TEMPLATE_TEST_CASE("replay subject multicasts values and replay", "", rpp::subje { const auto mock_3 = mock_observer_strategy{}; subj.get_observer().on_next(1); + CHECK(subj.get_value() == 1); CHECK(mock_1.get_received_values() == std::vector{10, 5, 1}); CHECK(mock_2.get_received_values() == std::vector{5, 1});