timer->expires_from_now(std::chrono::seconds(seconds)); 1. 2. 崩溃堆栈: std::size_t expires_from_now(const duration& expiry_time) { boost::system::error_code ec; std::size_t s = this->service.expires_from_now( this->implementation, expiry_time, ec); boost::asio::detail::throw_...
timer.expires_from_now(boost::posix_time::seconds(1)); 2.设置相对于当前时间的延迟时间 我们还可以使用steady_timer的expires_after成员函数,设置相对于现在的延迟时间。下面的代码示例设置了一个延迟2秒钟的定时器: cpp timer.expires_after(boost::chrono::seconds(2)); 七、设置定时器的回调函数 在之前的...
io_service io;//steady_timer t1(io);//t1.expires_from_now(boost::chrono::milliseconds(5000));//std::cout << t1.expires_at() << std::endl;//std::cout << t1.expires_from_now() << std::endl;///t1.wait();//t1.async_wait(//[](const boost::system::error_code& ec) {//...
steady_timer t1(io); t1.expires_from_now(boost::chrono::milliseconds(5000));//定时器,5000毫秒后定时器终止 std::cout << t1.expires_at() << std::endl;//查看终止的时间点,单位是纳秒 std::cout << t1.expires_from_now() << std::endl;//查看终止的时间长度,单位是纳秒 t1.wait();//...
steady_timer t1(io); t1.expires_from_now(boost::chrono::milliseconds(5000)); std::cout<< t1.expires_at() <<std::endl; std::cout<< t1.expires_from_now() <<std::endl;//t1.wait(); //异步等待,传入回调函数 t1.async_wait(
timer->expires_from_now(std::chrono::seconds(seconds)); 1. 2. 崩溃堆栈: std::size_t expires_from_now(const duration& expiry_time) { boost::system::error_code ec; std::size_t s = this->service.expires_from_now( this->implementation, expiry_time, ec); ...