|
Boost : |
From: Gavin Lambert (boost_at_[hidden])
Date: 2019-08-26 07:33:18
On 26/08/2019 19:17, JH wrote:
> My problem is I have wired behavior for expiry at absolute time, I
> have used deadline_timer for relative time for long time which works
> well, but I could not get the absolute time work, here is what I set
> up the timer to expire at 1minute 0 seconds:
>
> boost::posix_time::ptime posixTime(clockNow,
> boost::posix_time::hours(utcTime.time_of_day().hours()) +
> boost::posix_time::minutes(utcTime.time_of_day().minutes() + 1));
>
> expires_at(posixTime);
>
> async_wait(boost::bind(&ClockTimer::Handler, this,
> boost::asio::placeholders::error));
>
> So the expiry time is 2019-Aug-26 07:09:00, but when the timer
> expired, it called callback function 8 times consecutively, what could
> I be wrong here?
Are you calling async_wait more than once?
Each call to async_wait will queue up one callback when the timer
expires. They will "stack up" if you call it more than once.
Calling expires_at will cancel all previous async_wait calls (except in
some borderline cases when the timer was concurrently expiring), but the
callback function will still be called (with the operation_aborted code).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk