From fae3d42ee07b86e066cfa5362dc69bbbb7e3cdfc Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Fri, 3 Mar 2017 13:53:12 +0100 Subject: [PATCH] Add a r-value overload of freeze * Add checks for ensuring the propagation of the frozen property --- include/continuable/continuable-base.hpp | 23 ++++++++++++++--------- test/unit-test/test-continuable-base.cpp | 12 ++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/include/continuable/continuable-base.hpp b/include/continuable/continuable-base.hpp index aec0e4b..6dcf4ec 100644 --- a/include/continuable/continuable-base.hpp +++ b/include/continuable/continuable-base.hpp @@ -1510,16 +1510,12 @@ public: /// \endcond /// The destructor automatically invokes the continuable_base - /// if it wasn't released yet. + /// if it wasn't consumed yet. /// /// In order to invoke the continuable early you may call the /// continuable_base::done() method. /// - /// You may release the continuable_base through calling the corresponding - /// continuable_base::release method which prevents - /// the invocation on destruction but also makes the object unusable. - /// - /// The continuable_base::freeze method just disables the automatic + /// The continuable_base::freeze method disables the automatic /// invocation on destruction without invalidating the object. /// /// \since version 1.0.0 @@ -1772,7 +1768,7 @@ public: return detail::transforms::as_future(std::move(*this).materialize()); } - /// Invokes the continuation chain before the continuabl_base + /// Invokes the continuation chain before the continuable_base /// is destructed. This will release the object. /// /// \see continuable_base::~continuable_base() for further details about @@ -1788,7 +1784,7 @@ public: /// /// \returns Returns true when the continuable_base is frozen. /// - /// \see continuable_base::freeze() for further details. + /// \see continuable_base::freeze for further details. /// /// \note This method will trigger an assertion if the /// continuable_base was released already. @@ -1815,7 +1811,16 @@ public: /// continuable_base was released already. /// /// \since version 1.0.0 - void freeze(bool enabled = true) noexcept { ownership_.freeze(enabled); } + continuable_base& freeze(bool enabled = true) & noexcept { + ownership_.freeze(enabled); + return *this; + } + + /// \copydoc continuable_base::freeze + continuable_base&& freeze(bool enabled = true) && noexcept { + ownership_.freeze(enabled); + return std::move(*this); + } private: void release() noexcept { ownership_.release(); } diff --git a/test/unit-test/test-continuable-base.cpp b/test/unit-test/test-continuable-base.cpp index 8e7076c..5b83da7 100644 --- a/test/unit-test/test-continuable-base.cpp +++ b/test/unit-test/test-continuable-base.cpp @@ -90,6 +90,18 @@ TYPED_TEST(single_dimension_tests, are_not_finished_when_not_continued) { } } +TYPED_TEST(single_dimension_tests, freeze_is_kept_across_the_chain) { + { + auto chain = this->supply().freeze().then([=] { return this->supply(); }); + ASSERT_TRUE(chain.is_frozen()); + } + + { + auto chain = this->supply().freeze().then(this->supply()); + ASSERT_TRUE(chain.is_frozen()); + } +} + TYPED_TEST(single_dimension_tests, are_chainable) { EXPECT_ASYNC_RESULT(this->supply().then([] { return; // void