用一个 deadline_timer 在将来的200秒到期时间 async_wait 处理程序触发你可以调用你想要的任何功能
deadline_timer
async_wait
#include <boost/asio.hpp> #include <iostream> class Timer { public: explicit Timer(boost::asio::io_service& io_service) : _timer( io_service ) { this->wait(); } private: void wait() { _timer.expires_from_now(boost::posix_time::seconds(5)); _timer.async_wait([&](const boost::system::error_code& error) { if (error) { std::cerr << "Could not wait: " << error << std::endl; return; } std::cout << "Done waiting!" << std::endl; this->wait(); }); } private: boost::asio::deadline_timer _timer; }; int main() { boost::asio::io_service io_service; Timer t{io_service}; io_service.run(); }