Add a r-value overload of freeze

* Add checks for ensuring the propagation of the frozen property
This commit is contained in:
Denis Blank 2017-03-03 13:53:12 +01:00
parent bf4335d602
commit fae3d42ee0
2 changed files with 26 additions and 9 deletions

View File

@ -1510,16 +1510,12 @@ public:
/// \endcond /// \endcond
/// The destructor automatically invokes the continuable_base /// 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 /// In order to invoke the continuable early you may call the
/// continuable_base::done() method. /// continuable_base::done() method.
/// ///
/// You may release the continuable_base through calling the corresponding /// The continuable_base::freeze method disables the automatic
/// 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
/// invocation on destruction without invalidating the object. /// invocation on destruction without invalidating the object.
/// ///
/// \since version 1.0.0 /// \since version 1.0.0
@ -1772,7 +1768,7 @@ public:
return detail::transforms::as_future(std::move(*this).materialize()); 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. /// is destructed. This will release the object.
/// ///
/// \see continuable_base::~continuable_base() for further details about /// \see continuable_base::~continuable_base() for further details about
@ -1788,7 +1784,7 @@ public:
/// ///
/// \returns Returns true when the continuable_base is frozen. /// \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 /// \note This method will trigger an assertion if the
/// continuable_base was released already. /// continuable_base was released already.
@ -1815,7 +1811,16 @@ public:
/// continuable_base was released already. /// continuable_base was released already.
/// ///
/// \since version 1.0.0 /// \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: private:
void release() noexcept { ownership_.release(); } void release() noexcept { ownership_.release(); }

View File

@ -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) { TYPED_TEST(single_dimension_tests, are_chainable) {
EXPECT_ASYNC_RESULT(this->supply().then([] { EXPECT_ASYNC_RESULT(this->supply().then([] {
return; // void return; // void