diff --git a/include/rest_rpc/asio_util.hpp b/include/rest_rpc/asio_util.hpp index 393e906..de5fc6b 100644 --- a/include/rest_rpc/asio_util.hpp +++ b/include/rest_rpc/asio_util.hpp @@ -1,4 +1,5 @@ #pragma once +#include "io_context_pool.hpp" #include "traits.h" #include "use_asio.hpp" @@ -29,6 +30,18 @@ template inline auto sync_wait(auto executor, Coro &&coro) { return async_future(executor, std::forward(coro)).get(); } +template inline auto async_start(Coro &&coro) { + async_start(get_global_executor(), std::forward(coro)); +} + +template inline auto async_future(Coro &&coro) { + return async_future(get_global_executor(), std::forward(coro)); +} + +template inline auto sync_wait(Coro &&coro) { + return sync_wait(get_global_executor(), std::forward(coro)); +} + inline auto async_start(auto executor, auto &&coro, auto callback) { using R = typename std::remove_cvref_t::value_type; if constexpr (std::is_void_v) { diff --git a/tests/test_rest_rpc.cpp b/tests/test_rest_rpc.cpp index 92f57f3..120ae01 100644 --- a/tests/test_rest_rpc.cpp +++ b/tests/test_rest_rpc.cpp @@ -94,7 +94,7 @@ asio::awaitable 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 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 get_last_rwtime_coro(std::shared_ptr conn) {