Conversation
| bool& flag; | ||
| void set_value() && noexcept { flag = true; } | ||
| void set_error(auto&&) && noexcept { unreachable("unexpected call to set_error"); } | ||
| void set_stopped() && noexcept { unreachable("unexpected call to set_stopped"); } |
There was a problem hiding this comment.
should this be qualified std::unreachable?
There was a problem hiding this comment.
No, there is an "unreachable" function above which deals with some clang-tidy-warnings about assert always failing: that's the point - the function shouldn't be called and if it is I want it to fail.
There was a problem hiding this comment.
of course the function was hidden by the review tool -- you've already merged, but I'd suggest a different name when you're in there again. I was expecting a runtime check (since that's what std::unreachable is) - this is more like 'unexpected_call_assert'
There was a problem hiding this comment.
I'll make this change on the PR for task (I just made the change but there is more to go into the PR).
| auto await_suspend(::std::coroutine_handle<PP> parent) noexcept { | ||
| this->scheduler.emplace( | ||
| this->template from_env<scheduler_type>(::beman::execution::get_env(parent.promise()))); | ||
| this->parent = ::std::move(parent); |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| this->parent = ::std::move(parent); | |
| this->parent = ::std::move(parent); |
| return this->no_completion_set() | ||
| ? this->handle_stopped(this->parent.address()) | ||
| : ::std::move(this->parent) | ||
| ; |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| return this->no_completion_set() | |
| ? this->handle_stopped(this->parent.address()) | |
| : ::std::move(this->parent) | |
| ; | |
| return this->no_completion_set() ? this->handle_stopped(this->parent.address()) : ::std::move(this->parent); |
| ::std::optional<scheduler_type> scheduler; | ||
| ::beman::task::detail::handle<Promise> handle; | ||
| ::std::coroutine_handle<> parent{}; | ||
| auto (*handle_stopped)(void*)noexcept -> ::std::coroutine_handle<> = nullptr; |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| auto (*handle_stopped)(void*)noexcept -> ::std::coroutine_handle<> = nullptr; | |
| auto (*handle_stopped)(void*) noexcept -> ::std::coroutine_handle<> = nullptr; |
| std::coroutine_handle<> unhandled_stopped() { | ||
| return this->get_state()->complete(); | ||
| } |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| std::coroutine_handle<> unhandled_stopped() { | |
| return this->get_state()->complete(); | |
| } | |
| std::coroutine_handle<> unhandled_stopped() { return this->get_state()->complete(); } |
| ::beman::task::detail::sub_visit<2u>([]<typename E>(E& error) { | ||
| if constexpr (::std::same_as<::std::remove_cvref_t<E>, ::std::exception_ptr>) | ||
| std::rethrow_exception(::std::move(error)); | ||
| else | ||
| throw ::std::move(error); | ||
| }, this->result); |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| ::beman::task::detail::sub_visit<2u>([]<typename E>(E& error) { | |
| if constexpr (::std::same_as<::std::remove_cvref_t<E>, ::std::exception_ptr>) | |
| std::rethrow_exception(::std::move(error)); | |
| else | |
| throw ::std::move(error); | |
| }, this->result); | |
| ::beman::task::detail::sub_visit<2u>( | |
| []<typename E>(E& error) { | |
| if constexpr (::std::same_as<::std::remove_cvref_t<E>, ::std::exception_ptr>) | |
| std::rethrow_exception(::std::move(error)); | |
| else | |
| throw ::std::move(error); | |
| }, | |
| this->result); |
| assert(rc); | ||
| [[maybe_unused]] auto [value] = rc.value_or(std::tuple{0}); | ||
| assert(value == 17); | ||
|
|
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| } | |
tests/beman/task/task.test.cpp
Outdated
| } | ||
|
|
||
| auto test_cancel() { | ||
| auto rc = ex::sync_wait([]() -> ex::task<> { | ||
| bool stopped{}; | ||
| co_await ( | ||
| []()->ex::task<void> { co_await ex::just_stopped(); }() | ||
| | ex::upon_stopped([&stopped]() { stopped = true; }) | ||
| ); | ||
| assert(stopped); | ||
| }()); | ||
| } |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| } | |
| auto test_cancel() { | |
| auto rc = ex::sync_wait([]() -> ex::task<> { | |
| bool stopped{}; | |
| co_await ( | |
| []()->ex::task<void> { co_await ex::just_stopped(); }() | |
| | ex::upon_stopped([&stopped]() { stopped = true; }) | |
| ); | |
| assert(stopped); | |
| }()); | |
| } | |
| auto test_cancel() { | |
| auto rc = ex::sync_wait([]() -> ex::task<> { | |
| bool stopped{}; | |
| co_await ([]() -> ex::task<void> { co_await ex::just_stopped(); }() | | |
| ex::upon_stopped([&stopped]() { stopped = true; })); | |
| assert(stopped); | |
| }()); | |
| } |
tests/beman/task/task.test.cpp
Outdated
| auto test_indirect_cancel() { | ||
| // This approach uses symmetric transfer | ||
| auto rc = ex::sync_wait([]() -> ex::task<> { | ||
| std::cout << "indirect cancel\n" << std::unitbuf; | ||
| bool stopped{}; | ||
| std::cout << "outer co_await\n"; | ||
| co_await ( | ||
| []()->ex::task<void> { | ||
| std::cout << "middle co_await\n"; | ||
| co_await []()->ex::task<void> { | ||
| std::cout << "inner stopping\n"; | ||
| co_await ex::just_stopped(); | ||
| std::cout << "inner after stopped\n"; | ||
| }(); | ||
| std::cout << "middle after co_await\n"; | ||
| }() | ||
| | ex::upon_stopped([&stopped]() { stopped = true; }) | ||
| ); | ||
| std::cout << "outer after co_await\n"; | ||
| assert(stopped); | ||
| }()); | ||
| } |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| auto test_indirect_cancel() { | |
| // This approach uses symmetric transfer | |
| auto rc = ex::sync_wait([]() -> ex::task<> { | |
| std::cout << "indirect cancel\n" << std::unitbuf; | |
| bool stopped{}; | |
| std::cout << "outer co_await\n"; | |
| co_await ( | |
| []()->ex::task<void> { | |
| std::cout << "middle co_await\n"; | |
| co_await []()->ex::task<void> { | |
| std::cout << "inner stopping\n"; | |
| co_await ex::just_stopped(); | |
| std::cout << "inner after stopped\n"; | |
| }(); | |
| std::cout << "middle after co_await\n"; | |
| }() | |
| | ex::upon_stopped([&stopped]() { stopped = true; }) | |
| ); | |
| std::cout << "outer after co_await\n"; | |
| assert(stopped); | |
| }()); | |
| } | |
| auto test_indirect_cancel() { | |
| // This approach uses symmetric transfer | |
| auto rc = ex::sync_wait([]() -> ex::task<> { | |
| std::cout << "indirect cancel\n" << std::unitbuf; | |
| bool stopped{}; | |
| std::cout << "outer co_await\n"; | |
| co_await ([]() -> ex::task<void> { | |
| std::cout << "middle co_await\n"; | |
| co_await []() -> ex::task<void> { | |
| std::cout << "inner stopping\n"; | |
| co_await ex::just_stopped(); | |
| std::cout << "inner after stopped\n"; | |
| }(); | |
| std::cout << "middle after co_await\n"; | |
| }() | ex::upon_stopped([&stopped]() { stopped = true; })); | |
| std::cout << "outer after co_await\n"; | |
| assert(stopped); | |
| }()); |
| }()); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| } // namespace | |
tests/beman/task/task.test.cpp
Outdated
| } | ||
| } | ||
|
|
||
| auto main() -> int{ |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| auto main() -> int{ | |
| auto main() -> int { |
No description provided.