Commit 10d69890 authored by Krzysztof Kozielczyk's avatar Krzysztof Kozielczyk Committed by Facebook GitHub Bot

Add missing return in AsyncPipe move assignment operator

Summary:
I'm using AsyncPipe heavily in D22593723. At one iteration I needed to assign with move a holding object and it wouldn't compile because the operator doesn't return any value

Here's the error: `folly/experimental/coro/AsyncPipe.h:54:3: error: control reaches end of non-void function [-Werror,-Wreturn-type]`

Reviewed By: yfeldblum

Differential Revision: D22593724

fbshipit-source-id: 53f27b95c1dff0068a375291d4ee6f445f892dd9
parent e050deab
......@@ -50,6 +50,7 @@ class AsyncPipe {
AsyncPipe& operator=(AsyncPipe&& pipe) {
std::move(*this).close();
queue_ = std::move(pipe.queue_);
return *this;
}
static std::pair<folly::coro::AsyncGenerator<T&&>, AsyncPipe<T>> create() {
......
......@@ -115,6 +115,33 @@ TEST(AsyncPipeTest, PublishConsumeDestroy) {
}());
}
TEST(AsyncPipeTest, PublishConsumeWithMoves) {
auto [generator, pipe1] = folly::coro::AsyncPipe<int>::create();
for (int i = 0; i < 2; ++i) {
EXPECT_TRUE(pipe1.write(i));
}
// Move constructor
auto pipe2 = std::move(pipe1);
for (int i = 2; i < 4; ++i) {
EXPECT_TRUE(pipe2.write(i));
}
// Move assignment (optional forces the assignment)
std::optional<folly::coro::AsyncPipe<int>> pipe3;
pipe3 = std::move(pipe2);
for (int i = 4; i < 6; ++i) {
EXPECT_TRUE(pipe3->write(i));
}
// Should still read all values
folly::coro::blockingWait(
[generator = std::move(generator)]() mutable -> folly::coro::Task<void> {
for (int i = 0; i < 6; ++i) {
auto val = co_await generator.next();
EXPECT_TRUE(val);
EXPECT_EQ(*val, i);
}
}());
}
TEST(AsyncPipeTest, BrokenPipe) {
auto pipe = folly::coro::AsyncPipe<int>::create();
EXPECT_TRUE(pipe.second.write(0));
......
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