diff --git a/include/continuable/detail/expected.hpp b/include/continuable/detail/expected.hpp index 371ecbd..7092d78 100644 --- a/include/continuable/detail/expected.hpp +++ b/include/continuable/detail/expected.hpp @@ -204,7 +204,7 @@ public: return *this; } expected& operator=(types::error_type error) { - set_error(std::move(error)); + set_exception(std::move(error)); return *this; } @@ -226,7 +226,7 @@ public: init(std::move(value)); set(detail::slot_t::value); } - void set_error(types::error_type error) { + void set_exception(types::error_type error) { weak_destroy(); init(std::move(error)); set(detail::slot_t::error); diff --git a/test/unit-test/test-continuable-await.cpp b/test/unit-test/test-continuable-await.cpp index 8758029..9e87407 100644 --- a/test/unit-test/test-continuable-await.cpp +++ b/test/unit-test/test-continuable-await.cpp @@ -23,6 +23,10 @@ #ifdef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE +#ifndef CONTINUABLE_WITH_NO_EXCEPTIONS +#include +#endif // CONTINUABLE_WITH_NO_EXCEPTIONS + #include "test-continuable.hpp" namespace std { @@ -75,4 +79,44 @@ TYPED_TEST(single_dimension_tests, are_awaitable) { }))); } +#ifndef CONTINUABLE_WITH_NO_EXCEPTIONS + +struct await_exception : std::exception { + char const* what() const noexcept override { + return "await_exception"; + } + + bool operator==(await_exception const&) const noexcept { + return true; + } +}; + +/// Resolves the given promise asynchonously through an exception +template +void resolve_async_exceptional(S&& supplier, T&& promise) { + co_await supplier(); + + ASSERT_THROW(co_await supplier().then([] { throw await_exception{}; }), + await_exception); + + promise.set_value(); + co_return; +} + +TYPED_TEST(single_dimension_tests, are_awaitable_with_exceptions) { + auto const& supply = [&] { + // Supplies the current tested continuable + return this->supply(); + }; + + ASSERT_ASYNC_COMPLETION( + this->supply().then(cti::make_continuable([&](auto&& promise) { + // Resolve the cotinuable through a coroutine + resolve_async_exceptional(supply, + std::forward(promise)); + }))); +} + +#endif // CONTINUABLE_WITH_NO_EXCEPTIONS + #endif // CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE