fix for msvc

This commit is contained in:
qicosmos
2025-09-30 11:24:41 +08:00
parent 6675376cdd
commit 179f7767bf
2 changed files with 16 additions and 12 deletions
+3
View File
@@ -174,6 +174,7 @@ private:
} }
} }
} }
co_return;
} }
template <typename R, typename Arg, typename F, typename Self> template <typename R, typename Arg, typename F, typename Self>
@@ -213,6 +214,7 @@ private:
} }
} }
} }
co_return;
} }
template <typename R, typename Args, typename F, typename Self> template <typename R, typename Args, typename F, typename Self>
@@ -266,6 +268,7 @@ private:
} }
} }
} }
co_return;
} }
std::unordered_map<uint32_t, std::function<asio::awaitable<void>( std::unordered_map<uint32_t, std::function<asio::awaitable<void>(
+13 -12
View File
@@ -40,6 +40,17 @@ int round1(int i) { return i; }
std::string_view echo_sv(std::string_view str) { return str; } std::string_view echo_sv(std::string_view str) { return str; }
template<auto func>
asio::awaitable<void> response(auto ctx) {
auto ec = co_await ctx.response<func>("test");
if (ec) {
REST_LOG_ERROR << "response error: " << ec.message();
}
ec = co_await ctx.response<func>("test");
REST_LOG_ERROR << ec.message();
CHECK(ec);
}
std::string_view delay_response(std::string_view str) { std::string_view delay_response(std::string_view str) {
auto &ctx = rpc_context::context(); auto &ctx = rpc_context::context();
// set_delay before response in another thread // set_delay before response in another thread
@@ -52,18 +63,8 @@ std::string_view delay_response(std::string_view str) {
// REST_LOG_ERROR << "response error: " << ec.message(); // REST_LOG_ERROR << "response error: " << ec.message();
// } // }
auto executor = ctx.get_executor(); auto executor = ctx.get_executor();
auto coro = [ctx = std::move(ctx)]() mutable -> asio::awaitable<void> { // async_start(executor, response<delay_response>(std::move(ctx)));
auto ec = co_await ctx.response<delay_response>("test"); asio::co_spawn(executor, response<delay_response>(std::move(ctx)), asio::detached);
if (ec) {
REST_LOG_ERROR << "response error: " << ec.message();
}
ec = co_await ctx.response<delay_response>("test");
REST_LOG_ERROR << ec.message();
CHECK(ec);
};
async_start(executor, std::move(coro));
// asio::co_spawn(executor, std::move(coro), asio::detached);
}); });
thd.detach(); thd.detach();