]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/example/cpp14/deferred/deferred_4.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / asio / example / cpp14 / deferred / deferred_4.cpp
1 //
2 // deferred_4.cpp
3 // ~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10
11 #include <boost/asio.hpp>
12 #include <boost/asio/experimental/deferred.hpp>
13 #include <iostream>
14
15 using boost::asio::experimental::deferred;
16
17 template <typename CompletionToken>
18 auto async_wait_twice(boost::asio::steady_timer& timer, CompletionToken&& token)
19 {
20 return timer.async_wait(
21 deferred(
22 [&](boost::system::error_code ec)
23 {
24 std::cout << "first timer wait finished: " << ec.message() << "\n";
25 timer.expires_after(std::chrono::seconds(1));
26 return timer.async_wait(deferred);
27 }
28 )
29 )(
30 deferred(
31 [&](boost::system::error_code ec)
32 {
33 std::cout << "second timer wait finished: " << ec.message() << "\n";
34 return deferred.values(42);
35 }
36 )
37 )(
38 std::forward<CompletionToken>(token)
39 );
40 }
41
42 int main()
43 {
44 boost::asio::io_context ctx;
45
46 boost::asio::steady_timer timer(ctx);
47 timer.expires_after(std::chrono::seconds(1));
48
49 async_wait_twice(
50 timer,
51 [](int result)
52 {
53 std::cout << "result is " << result << "\n";
54 }
55 );
56
57 ctx.run();
58
59 return 0;
60 }