timer.cpp 583 B

1234567891011121314151617181920212223242526272829
  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. #include <iostream>
  11. #include <boost/asio.hpp>
  12. void print(const boost::system::error_code& /*e*/)
  13. {
  14. std::cout << "Hello, world!" << std::endl;
  15. }
  16. int main()
  17. {
  18. boost::asio::io_context io;
  19. boost::asio::steady_timer t(io, boost::asio::chrono::seconds(5));
  20. t.async_wait(&print);
  21. io.run();
  22. return 0;
  23. }