mirror of
https://github.com/qicosmos/rest_rpc.git
synced 2026-08-29 08:34:47 +08:00
simplify
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "io_context_pool.hpp"
|
||||
#include "traits.h"
|
||||
#include "use_asio.hpp"
|
||||
|
||||
@@ -29,6 +30,18 @@ template <typename Coro> inline auto sync_wait(auto executor, Coro &&coro) {
|
||||
return async_future(executor, std::forward<Coro>(coro)).get();
|
||||
}
|
||||
|
||||
template <typename Coro> inline auto async_start(Coro &&coro) {
|
||||
async_start(get_global_executor(), std::forward<Coro>(coro));
|
||||
}
|
||||
|
||||
template <typename Coro> inline auto async_future(Coro &&coro) {
|
||||
return async_future(get_global_executor(), std::forward<Coro>(coro));
|
||||
}
|
||||
|
||||
template <typename Coro> inline auto sync_wait(Coro &&coro) {
|
||||
return sync_wait(get_global_executor(), std::forward<Coro>(coro));
|
||||
}
|
||||
|
||||
inline auto async_start(auto executor, auto &&coro, auto callback) {
|
||||
using R = typename std::remove_cvref_t<decltype(coro)>::value_type;
|
||||
if constexpr (std::is_void_v<R>) {
|
||||
|
||||
@@ -94,7 +94,7 @@ asio::awaitable<std::string> delay_response2(std::string_view str) {
|
||||
REST_LOG_INFO << ret.message();
|
||||
CHECK(ret);
|
||||
};
|
||||
sync_wait(get_global_executor(), coro());
|
||||
sync_wait(coro());
|
||||
|
||||
rpc_context ctx; // right, created in io thread.
|
||||
co_await ctx.response(str);
|
||||
@@ -244,7 +244,7 @@ asio::awaitable<void> test_router() {
|
||||
CHECK(result1.ec == rpc_errc::ok);
|
||||
}
|
||||
|
||||
TEST_CASE("test router") { sync_wait(get_global_executor(), test_router()); }
|
||||
TEST_CASE("test router") { sync_wait(test_router()); }
|
||||
|
||||
asio::awaitable<void>
|
||||
get_last_rwtime_coro(std::shared_ptr<rpc_connection> conn) {
|
||||
|
||||
Reference in New Issue
Block a user