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

Function as_tuple_test

test/as_tuple.cpp:27–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25#include "unit_test.hpp"
26
27void as_tuple_test()
28{
29 boost::asio::io_context io1;
30 boost::asio::io_context io2;
31 boost::asio::system_timer timer1(io1);
32 int count = 0;
33
34 timer1.expires_after(boost::asio::chrono::seconds(0));
35 timer1.async_wait(
36 boost::asio::as_tuple(
37 boost::asio::bind_executor(io2.get_executor(),
38 [&count](std::tuple<boost::system::error_code>)
39 {
40 ++count;
41 })));
42
43 BOOST_ASIO_CHECK(count == 0);
44
45 io1.run();
46
47 BOOST_ASIO_CHECK(count == 0);
48
49 io2.run();
50
51 BOOST_ASIO_CHECK(count == 1);
52
53 timer1.async_wait(
54 boost::asio::as_tuple(
55 boost::asio::bind_executor(io2.get_executor(),
56 boost::asio::deferred)))(
57 [&count](std::tuple<boost::system::error_code>)
58 {
59 ++count;
60 });
61
62 BOOST_ASIO_CHECK(count == 1);
63
64 io1.restart();
65 io1.run();
66
67 BOOST_ASIO_CHECK(count == 1);
68
69 io2.restart();
70 io2.run();
71
72 BOOST_ASIO_CHECK(count == 2);
73
74# if defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS)
75 std::future<std::tuple<boost::system::error_code> > f = timer1.async_wait(
76 boost::asio::as_tuple(
77 boost::asio::bind_executor(io2.get_executor(),
78 boost::asio::use_future)));
79
80 BOOST_ASIO_CHECK(f.wait_for(std::chrono::seconds(0))
81 == std::future_status::timeout);
82
83 io1.restart();
84 io1.run();

Callers

nothing calls this directly

Calls 5

restartMethod · 0.80
expires_afterMethod · 0.45
async_waitMethod · 0.45
get_executorMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected