Commit 4ac6c276 authored by Jason Rahman's avatar Jason Rahman Committed by Facebook Github Bot

Support move-only types in SemiFuture::promise_type

Summary:
The SemiFuture::promise_type class didn't properly handle move only
types in return_value(). Added overload to handle T&& case properly.

Reviewed By: lewissbaker

Differential Revision: D12837450

fbshipit-source-id: 74edbb2d9de32abc2859f337047ca4e32414de7f
parent df8f0965
......@@ -321,8 +321,9 @@ TEST(Coro, Baton) {
EXPECT_EQ(42, std::move(future).get());
}
coro::Task<int> taskFuture(int value) {
co_return co_await folly::makeFuture<int>(std::move(value));
template <class Type>
coro::Task<Type> taskFuture(Type value) {
co_return co_await folly::makeFuture<Type>(std::move(value));
}
TEST(Coro, FulfilledFuture) {
......@@ -332,4 +333,14 @@ TEST(Coro, FulfilledFuture) {
&executor);
EXPECT_EQ(42, value);
}
TEST(Coro, MoveOnlyReturn) {
ManualExecutor executor;
auto value = taskFuture(std::make_unique<int>(42))
.scheduleOn(&executor)
.start()
.via(&executor)
.getVia(&executor);
EXPECT_EQ(42, *value);
}
#endif
......@@ -847,7 +847,7 @@ class SemiFuture : private futures::detail::FutureBase<T> {
promise_.setValue(value);
}
void return_value(T& value) {
void return_value(T&& value) {
promise_.setValue(std::move(value));
}
......
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