MCPcopy Create free account
hub / github.com/boostorg/asio / different_execs

Function different_execs

test/experimental/coro/executor.cpp:34–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32
33template <typename T>
34void different_execs()
35{
36 boost::asio::thread_pool th_ctx{1u};
37 boost::asio::io_context ctx;
38
39 auto o = std::make_optional(
40 boost::asio::prefer(th_ctx.get_executor(),
41 boost::asio::execution::outstanding_work.tracked));
42
43 static bool ran_inner = false, ran_outer = false;
44
45 struct c_inner_t
46 {
47 auto operator()(boost::asio::any_io_executor e) -> boost::asio::experimental::coro<T>
48 {
49 auto p = e.target<boost::asio::thread_pool::executor_type>();
50 BOOST_ASIO_CHECKPOINT();
51 BOOST_ASIO_CHECK(p);
52 BOOST_ASIO_CHECK(p->running_in_this_thread());
53 ran_inner = true;
54 co_return;
55 };
56
57 };
58
59 c_inner_t c_inner;
60
61 struct c_outer_t
62 {
63
64 auto operator()(boost::asio::any_io_executor e, int,
65 boost::asio::experimental::coro<T> tp)
66 -> boost::asio::experimental::coro<void>
67 {
68 auto p = e.target<boost::asio::io_context::executor_type>();
69
70 BOOST_ASIO_CHECK(p);
71 BOOST_ASIO_CHECK(p->running_in_this_thread());
72 BOOST_ASIO_CHECKPOINT();
73
74 co_await tp;
75
76 BOOST_ASIO_CHECKPOINT();
77 BOOST_ASIO_CHECK(p->running_in_this_thread());
78
79 ran_outer = true;
80 };
81 };
82
83 c_outer_t c_outer;
84
85 bool ran = false;
86 std::exception_ptr ex;
87
88 auto c = c_outer(ctx.get_executor(), 10, c_inner(th_ctx.get_executor()));
89 c.async_resume(
90 [&](std::exception_ptr e)
91 {

Callers

nothing calls this directly

Calls 7

preferFunction · 0.50
get_executorMethod · 0.45
async_resumeMethod · 0.45
runMethod · 0.45
resetMethod · 0.45
stopMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected