|
Boost Users : |
From: Longyu Mei (lmei007_at_[hidden])
Date: 2008-05-28 10:14:54
I am reading asio tutorial. Cannot understand the
usage of async_wait() function on Timer.3 sample.
http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/tutorial/tuttimer3/src.html
//////////////////
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;
}
/////////////////
in the main(), the async_wait() will not be invoked
until the io.run() is called.
But inside the print() there is a async_wait() call.
Why we don't need run() to trigger it?
thanks,
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net