Commit 85e4e439 authored by Doug Rabson's avatar Doug Rabson Committed by Facebook GitHub Bot

Support non-copyable types in folly::coro::timed_wait

Summary: If timed_wait is called with an awaitable that has a non-copyable return value then we must std::move the result.

Reviewed By: iahs

Differential Revision: D25222893

fbshipit-source-id: bd3c0ca19d182a464ad4b430f1792dcfff54ffdf
parent 15de336d
...@@ -65,9 +65,7 @@ timed_wait(Awaitable awaitable, Duration duration) { ...@@ -65,9 +65,7 @@ timed_wait(Awaitable awaitable, Duration duration) {
if (!result.hasValue() && !result.hasException()) { if (!result.hasValue() && !result.hasException()) {
co_return folly::none; co_return folly::none;
} }
// clang-format off co_return std::move(*result);
co_return *result;
// clang-format on
} }
} // namespace coro } // namespace coro
......
...@@ -354,6 +354,19 @@ TEST_F(CoroTest, TimedWaitKeepAlive) { ...@@ -354,6 +354,19 @@ TEST_F(CoroTest, TimedWaitKeepAlive) {
EXPECT_LE(duration, std::chrono::seconds{30}); EXPECT_LE(duration, std::chrono::seconds{30});
} }
TEST_F(CoroTest, TimedWaitNonCopyable) {
auto task = []() -> coro::Task<std::unique_ptr<int>> {
co_return std::make_unique<int>(42);
}();
EXPECT_EQ(
42,
**coro::blockingWait(
[&]() -> coro::Task<folly::Optional<std::unique_ptr<int>>> {
co_return co_await coro::timed_wait(
std::move(task), std::chrono::seconds{60});
}()));
}
template <int value> template <int value>
struct AwaitableInt { struct AwaitableInt {
bool await_ready() const { return true; } bool await_ready() const { return true; }
......
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