diff --git a/include/execpools/asio/asio_thread_pool.hpp b/include/execpools/asio/asio_thread_pool.hpp index 5c4085e5b..2bf42ce92 100644 --- a/include/execpools/asio/asio_thread_pool.hpp +++ b/include/execpools/asio/asio_thread_pool.hpp @@ -30,6 +30,12 @@ namespace execpools { return static_cast( asio_impl::query(executor_, asio_impl::execution::occupancy)); } + + [[nodiscard]] + auto get_executor() const { + return executor_; + } + private: [[nodiscard]] static constexpr auto forward_progress_guarantee() -> stdexec::forward_progress_guarantee { diff --git a/test/execpools/test_asio_thread_pool.cpp b/test/execpools/test_asio_thread_pool.cpp index 9b54586e6..253421b80 100644 --- a/test/execpools/test_asio_thread_pool.cpp +++ b/test/execpools/test_asio_thread_pool.cpp @@ -29,6 +29,8 @@ #include +#include + namespace ex = stdexec; namespace { @@ -168,4 +170,20 @@ namespace { REQUIRE(value.data() == output.data()); CHECK(output == std::array{1.0, 3.0, 2.0, 0.0}); } + + TEST_CASE("asiothreadpool with asioexec interoperability") { + const auto current_thread_id = std::this_thread::get_id(); + + execpools::asio_thread_pool pool{1ul}; + asioexec::asio_impl::system_timer timer{pool.get_executor()}; + const auto [other_thread_id] = + stdexec::sync_wait(timer.async_wait(asioexec::use_sender) | stdexec::then([](auto&&...) { + return std::this_thread::get_id(); + })) + .value(); + REQUIRE(current_thread_id != other_thread_id); + + // demo to access underlying execution context + asioexec::asio_impl::query(pool.get_executor(), asioexec::asio_impl::execution::context_t{}).stop(); + } } // namespace