Created
May 18, 2014 07:40
-
-
Save maksadbek/b3e8d7103ab4b2080ff3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/asio.hpp> | |
#include <boost/date_time/posix_time/posix_time.hpp> | |
void print(const boost::system::error_code&){ | |
std::cout<<"Hello, boost!"<<std::endl; | |
} | |
int main(){ | |
boost::asio::io_service io; | |
boost::asio::deadline_timer t(io, boost::posix_time::seconds(5)); | |
t.async_wait(&print); | |
io.run(); | |
} | |
/* boost time 3 */ | |
#include <iostream> | |
#include <boost/asio.hpp> | |
#include <boost/bind.hpp> | |
#include <boost/date_time/posix_time/posix_time.hpp> | |
void print(const boost::system::error_code& /*e*/, | |
boost::asio::deadline_timer* t, int* count) | |
{ | |
if (*count < 5) | |
{ | |
std::cout << *count << "\n"; | |
++(*count); | |
t->expires_at(t->expires_at() + boost::posix_time::seconds(1)); | |
t->async_wait(boost::bind(print, | |
boost::asio::placeholders::error, t, count)); | |
} | |
} | |
int main() | |
{ | |
boost::asio::io_service io; | |
int count = 0; | |
boost::asio::deadline_timer t(io, boost::posix_time::seconds(1)); | |
t.async_wait(boost::bind(print, | |
boost::asio::placeholders::error, &t, &count)); | |
io.run(); | |
std::cout << "Final count is " << count << "\n"; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment