/***************五秒定时器****************/
#include
#include
boost::asio::io_service io;
//boost::asio::deadline_timer t1(io, boost::posix_time::seconds(5));
boost::asio::steady_timer t1(io);
int count = 0;
void start_time();
void start_time_handle(const boost::system::error_code& ec)
{
if (ec) {
return;
}
count++;
if (count >= 4) {
t1.cancel();
}
else {
start_time();
}
std::cout << "start_time_handle" << std::endl;
}
void start_time()
{
t1.expires_from_now(std::chrono::seconds(5));
t1.async_wait(std::bind(start_time_handle, std::placeholders::_1));
}
int main()
{
start_time();
//t1.async_wait(std::bind(Display, std::placeholders::_1, &t1));
//t1.async_wait([](const boost::system::error_code& ec) {
// if (ec) {
// return;
// }
// std::cout << "ssss" << std::endl;
// });
io.run();
}
/******************五秒之后定时器退出*********************/
#include
#include
int main()
{
boost::asio::io_service io;
boost::asio::deadline_timer t1(io, boost::posix_time::seconds(5));
//t1.async_wait(std::bind(Display, std::placeholders::_1, &t1));
t1.async_wait([](const boost::system::error_code& ec) {
if (ec) {
return;
}
std::cout << "ssss" << std::endl;
});
io.run();
}