Rename cancel() to stop() and make cancel() return a cancellation result instead

This commit is contained in:
Denis Blank 2020-04-05 00:22:30 +02:00
parent 77faf3120f
commit 33bfc490ef
5 changed files with 39 additions and 11 deletions

View File

@ -64,7 +64,7 @@ Result handling and
- \ref result - \ref result
- \ref rethrow - \ref rethrow
- \ref cancel - \ref cancel
- \ref terminate - \ref stop
- \ref make_result - \ref make_result
Special result types Special result types

View File

@ -1058,9 +1058,10 @@ inline exceptional_result rethrow(exception_t exception) {
} }
/// Can be used to cancel an asynchronous continuation chain, /// Can be used to cancel an asynchronous continuation chain,
/// no handler which comes after cancel was received won't be called. /// the next failure handler which comes after cancel will be called
/// with a default constructed exception_t object.
/// ///
/// The \ref empty_result returned by this function can be returned from /// The \ref cancellation_result returned by this function can be returned from
/// any result or failure handler in order to cancel the chain. /// any result or failure handler in order to cancel the chain.
/// ```cpp /// ```cpp
/// http_request("example.com") /// http_request("example.com")
@ -1091,7 +1092,16 @@ inline exceptional_result rethrow(exception_t exception) {
/// ///
/// \since 4.0.0 /// \since 4.0.0
/// ///
inline empty_result cancel() { inline cancellation_result cancel() {
return {};
}
/// Can be used to stop an asynchronous continuation chain,
/// no handler which comes after stop was received won't be called.
///
/// \since 4.0.0
///
inline empty_result stop() {
return {}; return {};
} }

View File

@ -110,6 +110,12 @@ TYPED_TEST(single_dimension_tests, are_not_finished_when_not_continued) {
return empty_result(); return empty_result();
})); }));
} }
{
ASSERT_ASYNC_INCOMPLETION(this->supply().then([] {
return stop();
}));
}
} }
TYPED_TEST(single_dimension_tests, are_not_finished_when_cancelling) { TYPED_TEST(single_dimension_tests, are_not_finished_when_cancelling) {

View File

@ -127,7 +127,7 @@ TYPED_TEST(single_dimension_tests, are_exceptions_partial_applyable) {
.fail([&]() -> empty_result { .fail([&]() -> empty_result {
EXPECT_FALSE(handled); EXPECT_FALSE(handled);
handled = true; handled = true;
return cancel(); return stop();
})); }));
ASSERT_TRUE(handled); ASSERT_TRUE(handled);
@ -138,7 +138,7 @@ TYPED_TEST(single_dimension_tests, are_exceptions_partial_applyable) {
.fail([&]() -> result<int, int> { .fail([&]() -> result<int, int> {
EXPECT_FALSE(handled); EXPECT_FALSE(handled);
handled = true; handled = true;
return cancel(); return stop();
})); }));
ASSERT_TRUE(handled); ASSERT_TRUE(handled);

View File

@ -63,17 +63,29 @@ TYPED_TEST(single_dimension_tests, multipath_result_is_throwable) {
} }
TYPED_TEST(single_dimension_tests, multipath_result_is_cancelable) { TYPED_TEST(single_dimension_tests, multipath_result_is_cancelable) {
ASSERT_ASYNC_INCOMPLETION(this->supply().then([]() -> empty_result { ASSERT_ASYNC_CANCELLATION(this->supply().then([]() -> cancellation_result {
// //
return cancel(); return cancel();
})); }));
ASSERT_ASYNC_INCOMPLETION(this->supply().then([]() -> result<> { ASSERT_ASYNC_CANCELLATION(this->supply().then([]() -> result<> {
// //
return cancel(); return cancel();
})); }));
} }
TYPED_TEST(single_dimension_tests, multipath_result_is_stoppable) {
ASSERT_ASYNC_INCOMPLETION(this->supply().then([]() -> empty_result {
//
return stop();
}));
ASSERT_ASYNC_INCOMPLETION(this->supply().then([]() -> result<> {
//
return stop();
}));
}
TYPED_TEST(single_dimension_tests, multipath_exception_is_recoverable) { TYPED_TEST(single_dimension_tests, multipath_exception_is_recoverable) {
EXPECT_ASYNC_RESULT( EXPECT_ASYNC_RESULT(
this->supply_exception(supply_test_exception(), identity<>{}) this->supply_exception(supply_test_exception(), identity<>{})
@ -115,19 +127,19 @@ TYPED_TEST(single_dimension_tests, multipath_exception_is_forwardable) {
})); }));
} }
TYPED_TEST(single_dimension_tests, multipath_exception_is_cancelable) { TYPED_TEST(single_dimension_tests, multipath_exception_is_stoppable) {
ASSERT_ASYNC_INCOMPLETION( ASSERT_ASYNC_INCOMPLETION(
this->supply_exception(supply_test_exception(), identity<int>{}) this->supply_exception(supply_test_exception(), identity<int>{})
.fail([](exception_t) -> empty_result { .fail([](exception_t) -> empty_result {
// //
return cancel(); return stop();
})); }));
ASSERT_ASYNC_INCOMPLETION( ASSERT_ASYNC_INCOMPLETION(
this->supply_exception(supply_test_exception(), identity<int>{}) this->supply_exception(supply_test_exception(), identity<int>{})
.fail([](exception_t) -> result<int> { .fail([](exception_t) -> result<int> {
// //
return cancel(); return stop();
})); }));
} }