Commit 126c1959 authored by Dmitry Zhuk's avatar Dmitry Zhuk Committed by Facebook GitHub Bot

Fix exception ignored by coro::Future<void>

Summary: If `coro::Promise<void>` completes with exception, `coro::Future<void>` should throw this exception, but currently it just ignores it.

Reviewed By: iahs

Differential Revision: D34211495

fbshipit-source-id: 99e2855646b907ac2a87c800bc8b9cb1eff82087
parent 36cd1d7e
...@@ -143,6 +143,8 @@ class Future { ...@@ -143,6 +143,8 @@ class Future {
T await_resume() { T await_resume() {
if constexpr (!std::is_void_v<T>) { if constexpr (!std::is_void_v<T>) {
return std::move(future_.state_.result.value()); return std::move(future_.state_.result.value());
} else {
future_.state_.result.throwIfFailed();
} }
} }
......
...@@ -49,6 +49,12 @@ CO_TEST(PromiseTest, ImmediateException) { ...@@ -49,6 +49,12 @@ CO_TEST(PromiseTest, ImmediateException) {
EXPECT_TRUE(res.hasException<std::runtime_error>()); EXPECT_TRUE(res.hasException<std::runtime_error>());
} }
CO_TEST(PromiseTest, ImmediateExceptionVoid) {
auto [promise, future] = coro::makePromiseContract<void>();
promise.setException(std::runtime_error(""));
EXPECT_THROW(co_await std::move(future), std::runtime_error);
}
CO_TEST(PromiseTest, SuspendValue) { CO_TEST(PromiseTest, SuspendValue) {
auto [promise, future] = coro::makePromiseContract<int>(); auto [promise, future] = coro::makePromiseContract<int>();
auto waiter = [](auto future) -> coro::Task<int> { auto waiter = [](auto future) -> coro::Task<int> {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment