Skip to content

Commit e942458

Browse files
committed
Stop requiring rvalue references for co_return
1 parent 066c72a commit e942458

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

test/async_work_test.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11

2-
#include <atomic>
3-
#include <functional>
4-
#include <stdexcept>
5-
#include <thread>
2+
#include <fcntl.h>
3+
#include <fmt/core.h>
4+
#include <fmt/ranges.h>
5+
#include <gtest/gtest.h>
66
#include <uv.h>
77

88
#include "test_util.h"
9-
109
#include "uvco/async_work.h"
1110
#include "uvco/loop/loop.h"
1211
#include "uvco/promise/promise.h"
1312

14-
#include <fcntl.h>
15-
#include <fmt/core.h>
16-
#include <fmt/ranges.h>
17-
#include <gtest/gtest.h>
13+
#include <atomic>
14+
#include <functional>
15+
#include <stdexcept>
16+
#include <thread>
1817
#include <vector>
1918

2019
namespace {
@@ -115,7 +114,8 @@ TEST(AsyncWorkTest, execptionThrownForValue) {
115114
}
116115

117116
TEST(AsyncWorkTest, workNotAwaited) {
118-
// Test that work on the threadpool finishes even if the main function returns early.
117+
// Test that work on the threadpool finishes even if the main function returns
118+
// early.
119119
bool workRan = false;
120120
auto work = [&workRan]() -> void {
121121
std::this_thread::sleep_for(std::chrono::milliseconds{10});

test/pqxx_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ constexpr std::string_view schemaTearDown = R"(
2222
DROP TABLE test;
2323
)";
2424

25-
constexpr std::string_view connectionString = "dbname=lbo";
25+
constexpr std::string_view connectionString = "dbname=lbo user=lbo";
2626

2727
// This test obviously only runs if you have a PostgreSQL server running. Change
2828
// the connection string to match your setup.

uvco/async_work.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Promise<R> submitWork(const Loop &loop, std::function<R()> work) {
3939
if (result->index() == 1) {
4040
std::rethrow_exception(std::get<std::exception_ptr>(*result));
4141
}
42-
co_return std::move(std::get<R>(*result));
42+
co_return std::get<R>(std::move(*result));
4343
}
4444

4545
template <>

uvco/promise/multipromise.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,20 +309,13 @@ template <typename T> class Generator {
309309
/// still moved into the generator's slot, but the generator is not resumed.
310310
/// Upon the next `co_await`, the returned `MultiPromiseAwaiter_` will
311311
/// immediately return the value without resuming the generator.
312-
YieldAwaiter_ yield_value(T &&value) {
312+
YieldAwaiter_ yield_value(T value) {
313313
BOOST_ASSERT(!core_->slot);
314314
core_->slot = std::move(value);
315315
core_->resume();
316316
return YieldAwaiter_{*core_};
317317
}
318318

319-
YieldAwaiter_ yield_value(const T &value) {
320-
BOOST_ASSERT(!core_->slot);
321-
core_->slot = value;
322-
core_->resume();
323-
return YieldAwaiter_{*core_};
324-
}
325-
326319
private:
327320
/// A `YieldAwaiter_` suspends a coroutine returning a MultiPromise (i.e. a
328321
/// generator) and resumes it when the value is read by the awaiting

uvco/promise/promise.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ template <typename T> class Coroutine {
310310

311311
/// Part of the coroutine protocol: Called by `co_return`. Schedules the
312312
/// awaiting coroutine for resumption.
313-
void return_value(T &&value) {
313+
void return_value(T value) {
314314
// Probably cancelled.
315315
if (core_->slot.has_value() && core_->slot->index() == 1) {
316316
return;

uvco/uds.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Promise<UnixStream> UnixStreamClient::connect(std::string_view path) {
4646
// open but not connected handle.
4747
try {
4848
UnixStream connection = co_await awaiter;
49-
co_return std::move(connection);
49+
co_return connection;
5050
} catch (const UvcoException &e) {
5151
maybeError = e;
5252
}

0 commit comments

Comments
 (0)