Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec.awaitables: fix completion sigs for void awaitables #96

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions include/beman/execution26/detail/get_completion_signatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ struct get_completion_signatures_t {
return typename sender_type::completion_signatures{};
else if constexpr (::beman::execution26::detail::
is_awaitable<sender_type, ::beman::execution26::detail::env_promise<decayed_env>>) {
return ::beman::execution26::completion_signatures<
::beman::execution26::set_value_t(
::beman::execution26::detail::
await_result_type<sender_type, ::beman::execution26::detail::env_promise<decayed_env>>),
::beman::execution26::set_error_t(::std::exception_ptr),
::beman::execution26::set_stopped_t()>{};
using result_type = ::beman::execution26::detail::
await_result_type<sender_type, ::beman::execution26::detail::env_promise<decayed_env>>;
if constexpr (::std::same_as<void, result_type>) {
return ::beman::execution26::completion_signatures<::beman::execution26::set_value_t(),
::beman::execution26::set_error_t(
::std::exception_ptr),
::beman::execution26::set_stopped_t()>{};
} else {
return ::beman::execution26::completion_signatures<::beman::execution26::set_value_t(result_type),
::beman::execution26::set_error_t(
::std::exception_ptr),
::beman::execution26::set_stopped_t()>{};
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/beman/execution26/exec-with-awaitable-senders.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ struct awaitable {
int await_resume() { return 1; }
};

struct void_awaitable {
bool await_ready() { return false; }
void await_suspend(std::coroutine_handle<> h) { h.resume(); }
void await_resume() {}
};

struct coroutine : std::coroutine_handle<promise> {
using promise_type = ::promise;
};
Expand Down Expand Up @@ -52,6 +58,14 @@ void test_sync_wait_awaitable() {
}
}

void test_sync_wait_void_awaitable() {
try {
ASSERT(exec::sync_wait(void_awaitable{}));
} catch (...) {
ASSERT(false);
}
}

coroutine test_mix_awaitable_and_sender() {
auto [just, value] = co_await exec::when_all(exec::just(0), awaitable{});
ASSERT(just == 0);
Expand All @@ -62,5 +76,6 @@ TEST(exec_with_awaitable_senders) {
test_await_tuple().resume();
test_await_void().resume();
test_sync_wait_awaitable();
test_sync_wait_void_awaitable();
test_mix_awaitable_and_sender().resume();
}