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

Function main

example/cpp14/parallel_group/wait_for_one_success.cpp:17–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
16
17int main()
18{
19 boost::asio::io_context ctx;
20
21 boost::asio::posix::stream_descriptor in(ctx, ::dup(STDIN_FILENO));
22 boost::asio::steady_timer timer(ctx, std::chrono::seconds(5));
23
24 char data[1024];
25
26 boost::asio::experimental::make_parallel_group(
27 [&](auto token)
28 {
29 return in.async_read_some(boost::asio::buffer(data), token);
30 },
31 [&](auto token)
32 {
33 return timer.async_wait(token);
34 }
35 ).async_wait(
36 boost::asio::experimental::wait_for_one_success(),
37 [](
38 std::array<std::size_t, 2> completion_order,
39 boost::system::error_code ec1, std::size_t n1,
40 boost::system::error_code ec2
41 )
42 {
43 switch (completion_order[0])
44 {
45 case 0:
46 {
47 std::cout << "descriptor finished: " << ec1 << ", " << n1 << "\n";
48 }
49 break;
50 case 1:
51 {
52 std::cout << "timer finished: " << ec2 << "\n";
53 }
54 break;
55 }
56 }
57 );
58
59 ctx.run();
60}
61
62#else // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
63int main() {}

Callers

nothing calls this directly

Calls 5

bufferFunction · 0.85
async_waitMethod · 0.45
async_read_someMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected