Commit d92bb4bb authored by Francesco Zoffoli's avatar Francesco Zoffoli Committed by Facebook GitHub Bot

Support move only objects in `collectAny`

Summary: `collectAny` does not compile when used with `Task`s that return move only objects

Reviewed By: yfeldblum

Differential Revision: D29137632

fbshipit-source-id: d8fd4f46d4c014c7492dcd2fb7fe84921db8aad0
parent 033fa8af
...@@ -296,7 +296,8 @@ auto collectAnyImpl( ...@@ -296,7 +296,8 @@ auto collectAnyImpl(
std::atomic<bool> resultHasBeenSet{false}; std::atomic<bool> resultHasBeenSet{false};
std::pair<std::size_t, folly::Try<collect_any_component_t<SemiAwaitables...>>> std::pair<std::size_t, folly::Try<collect_any_component_t<SemiAwaitables...>>>
firstCompletion{0, {}}; firstCompletion;
firstCompletion.first = size_t(-1);
co_await folly::coro::collectAll(folly::coro::co_withCancellation( co_await folly::coro::collectAll(folly::coro::co_withCancellation(
cancelToken, cancelToken,
folly::coro::co_invoke( folly::coro::co_invoke(
......
...@@ -1698,6 +1698,22 @@ TEST_F(CollectAnyTest, OneVoidTask) { ...@@ -1698,6 +1698,22 @@ TEST_F(CollectAnyTest, OneVoidTask) {
CHECK(completed); CHECK(completed);
} }
TEST_F(CollectAnyTest, MoveOnlyType) {
bool completed = false;
folly::coro::blockingWait([&]() -> folly::coro::Task<void> {
// Checks that the task actually runs and that move only results
// can be correctly returned
std::pair<std::size_t, folly::Try<std::unique_ptr<int>>> result =
co_await folly::coro::collectAny(
[&]() -> folly::coro::Task<std::unique_ptr<int>> {
completed = true;
co_return std::make_unique<int>(1);
}());
(void)result;
}());
CHECK(completed);
}
TEST_F(CollectAnyTest, CollectAnyDoesntCompleteUntilAllTasksComplete) { TEST_F(CollectAnyTest, CollectAnyDoesntCompleteUntilAllTasksComplete) {
folly::coro::Baton baton1; folly::coro::Baton baton1;
folly::coro::Baton baton2; folly::coro::Baton baton2;
......
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