An explanation is needed for this boost :: asio timer example

The third Boost asio tutorial has a line that shows how to update the timer and still prevent drift. The line is as follows:

 t->expires_at(t->expires_at() + boost::posix_time::seconds(1));

Maybe this is for me, but I could not find the documentation for the second use of e xpires_at()without parameters. expires_at(x)sets a new expiration, canceling any pending handlers. So, presumably expires_at () does what, return time of the last expiration? So, adding one second, if there should be a certain amount of ms, say n ms, then it will, in fact, be β€œsubtracted” from the next expiration from the moment the time is taken into account? What happens if the time taken to execute this handler is more than 1 second in this example? Does it work immediately?

+5
source share
1 answer

expires_at () returns the time when it is set to timeout. Thus, this will move the timeout 1 second later.

When you set the time with expires_at (x), you will get a return of 0 if it has already been called due to the elapsed time. If return is greater, then 0 indicates the number of canceled.

+2
source

All Articles