Skip to content

Commit 47185ef

Browse files
authored
[execpools,asio] add executor getter to be able to schedule asio functions (#1535)
1 parent 49d6ec2 commit 47185ef

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

include/execpools/asio/asio_thread_pool.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ namespace execpools {
3030
return static_cast<std::uint32_t>(
3131
asio_impl::query(executor_, asio_impl::execution::occupancy));
3232
}
33+
34+
[[nodiscard]]
35+
auto get_executor() const {
36+
return executor_;
37+
}
38+
3339
private:
3440
[[nodiscard]]
3541
static constexpr auto forward_progress_guarantee() -> stdexec::forward_progress_guarantee {

test/execpools/test_asio_thread_pool.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#include <execpools/asio/asio_thread_pool.hpp>
3131

32+
#include <asioexec/use_sender.hpp>
33+
3234
namespace ex = stdexec;
3335

3436
namespace {
@@ -168,4 +170,20 @@ namespace {
168170
REQUIRE(value.data() == output.data());
169171
CHECK(output == std::array{1.0, 3.0, 2.0, 0.0});
170172
}
173+
174+
TEST_CASE("asiothreadpool with asioexec interoperability") {
175+
const auto current_thread_id = std::this_thread::get_id();
176+
177+
execpools::asio_thread_pool pool{1ul};
178+
asioexec::asio_impl::system_timer timer{pool.get_executor()};
179+
const auto [other_thread_id] =
180+
stdexec::sync_wait(timer.async_wait(asioexec::use_sender) | stdexec::then([](auto&&...) {
181+
return std::this_thread::get_id();
182+
}))
183+
.value();
184+
REQUIRE(current_thread_id != other_thread_id);
185+
186+
// demo to access underlying execution context
187+
asioexec::asio_impl::query(pool.get_executor(), asioexec::asio_impl::execution::context_t{}).stop();
188+
}
171189
} // namespace

0 commit comments

Comments
 (0)