Discussion:
[asio-users] asio::deadline_timer does not call the handler if I change the time back
niXman
2012-04-14 07:49:19 UTC
Permalink
This simple code does not call the handler print () if I change the time back.
Is this normal?
How can I fix this behavior?

#include <iostream>
#include <boost/asio.hpp>

void print(const boost::system::error_code& /*e*/) {
std::cout << "Hello, world!" << 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();
return 0;
}

http://liveworkspace.org/code/5e35baafe00a0a7a47f51347a92d9110

Thanks.
--
Regards,
  niXman
Marat Abrarov
2012-04-14 08:22:44 UTC
Permalink
Post by niXman
This simple code does not call the handler print () if I change the time back.
Is this normal?
How can I fix this behavior?
This is an ancient question. I think it would be better if author of Asio adds the answer to the docs (for example, here http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/overview/timers.html).

In short, the answer is:
http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/reference/steady_timer.html

or (if you can't use the latest version of Boost.Asio) make it yourself (http://asio-samples.svn.sourceforge.net/viewvc/asio-samples/branches/steady_deadline_timer/include/ma/steady_deadline_timer.hpp?revision=509&view=markup inspired by http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/example/timers/tick_count_timer.cpp)

Regards,
Marat Abrarov.
niXman
2012-04-14 16:39:04 UTC
Permalink
Post by Marat Abrarov
Post by niXman
This simple code does not call the handler print () if I change the time back.
Is this normal?
How can I fix this behavior?
This is an ancient question. I think it would be better if author of Asio adds the answer to the docs (for example, here http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/overview/timers.html).
http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/reference/steady_timer.html
or (if you can't use the latest version of Boost.Asio) make it yourself (http://asio-samples.svn.sourceforge.net/viewvc/asio-samples/branches/steady_deadline_timer/include/ma/steady_deadline_timer.hpp?revision=509&view=markup inspired by http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/example/timers/tick_count_timer.cpp)
Thank you for your answer.
The problem is solved.
Post by Marat Abrarov
Regards,
Marat Abrarov.
------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
--
Regards,
  niXman
Loading...