]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/example/cpp03/tutorial/timer3/timer.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / asio / example / cpp03 / tutorial / timer3 / timer.cpp
CommitLineData
7c673cae
FG
1//
2// timer.cpp
3// ~~~~~~~~~
4//
b32b8144 5// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7c673cae
FG
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#include <boost/date_time/posix_time/posix_time.hpp>
15
16void print(const boost::system::error_code& /*e*/,
17 boost::asio::deadline_timer* t, int* count)
18{
19 if (*count < 5)
20 {
21 std::cout << *count << std::endl;
22 ++(*count);
23
24 t->expires_at(t->expires_at() + boost::posix_time::seconds(1));
25 t->async_wait(boost::bind(print,
26 boost::asio::placeholders::error, t, count));
27 }
28}
29
30int main()
31{
b32b8144 32 boost::asio::io_context io;
7c673cae
FG
33
34 int count = 0;
35 boost::asio::deadline_timer t(io, boost::posix_time::seconds(1));
36 t.async_wait(boost::bind(print,
37 boost::asio::placeholders::error, &t, &count));
38
39 io.run();
40
41 std::cout << "Final count is " << count << std::endl;
42
43 return 0;
44}