Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/execpools/asio/asio_thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ namespace execpools {
return static_cast<std::uint32_t>(
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 {
Expand Down
18 changes: 18 additions & 0 deletions test/execpools/test_asio_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include <execpools/asio/asio_thread_pool.hpp>

#include <asioexec/use_sender.hpp>

namespace ex = stdexec;

namespace {
Expand Down Expand Up @@ -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
Loading