]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/example/cpp03/tutorial/timer3/timer.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / asio / example / cpp03 / tutorial / timer3 / timer.cpp
1 //
2 // timer.cpp
3 // ~~~~~~~~~
4 //
5 // Copyright (c) 2003-2019 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 <iostream>
12 #include <boost/asio.hpp>
13 #include <boost/bind.hpp>
14
15 void print(const boost::system::error_code& /*e*/,
16 boost::asio::steady_timer* t, int* count)
17 {
18 if (*count < 5)
19 {
20 std::cout << *count << std::endl;
21 ++(*count);
22
23 t->expires_at(t->expiry() + boost::asio::chrono::seconds(1));
24 t->async_wait(boost::bind(print,
25 boost::asio::placeholders::error, t, count));
26 }
27 }
28
29 int main()
30 {
31 boost::asio::io_context io;
32
33 int count = 0;
34 boost::asio::steady_timer t(io, boost::asio::chrono::seconds(1));
35 t.async_wait(boost::bind(print,
36 boost::asio::placeholders::error, &t, &count));
37
38 io.run();
39
40 std::cout << "Final count is " << count << std::endl;
41
42 return 0;
43 }