Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7807967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:00:56+00:00 2026-06-02T03:00:56+00:00

In the official boost link below: http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/reference/deadline_timer.html . You can see we can renew

  • 0

In the official boost link below:
http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/reference/deadline_timer.html .

You can see we can renew a async deadline_timer before it expires. That’s fine, the code works:
when timer got renewed, the old async_wait got cancelled that’s fine but the annoy thing is when it’s cancelled, it still called the handler :

void handler(const boost::system::error_code& error)
{
  if (!error)
  {
    // Timer expired.
  }
}

...

// Construct a timer with an absolute expiry time.
boost::asio::deadline_timer timer(io_service,
    boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));

// Start an asynchronous wait.
timer.async_wait(handler);

Changing an active deadline_timer’s expiry time

Changing the expiry time of a timer while there are pending asynchronous waits causes those wait operations to be cancelled. To ensure that the action associated with the timer is performed only once, use something like this: used:

void on_some_event()
{
  if (my_timer.expires_from_now(seconds(5)) > 0)
  {
    // We managed to cancel the timer. Start new asynchronous wait.
    my_timer.async_wait(on_timeout);
  }
  else
  {
    // Too late, timer has already expired!
  }
}

void on_timeout(const boost::system::error_code& e)
{
  if (e != boost::asio::error::operation_aborted)
  {
    // Timer was not cancelled, take necessary action.
  }
}

I am wondering is there way to renew & cancel the old timer without letting the old timer calling the handler, in this case the on_timeout() function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:00:57+00:00Added an answer on June 2, 2026 at 3:00 am

    It can be fixed by adding one line check (see if it’s an abort/cancel event) before doing actual stuff:

    void handler1(const boost::system::error_code &e)
    {
        if (e != boost::asio::error::operation_aborted) // here is the important part
            {
                //do actual stuff here if it's not a cancel/abort event
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unfortunately official guide for creating Rails plugins is outdated: http://guides.rubyonrails.org/plugins.html and I didn't find
The official tutorial from http://www.antlr.org/wiki/display/ST/Five+minute+Introduction doesn't work because of DefaultTemplateLexer, how to fix ?
The official website seems only provided some tutorial on how to use: http://www.symfony-project.org But
The below is from the official BOOST docs. Why do I always get size
In official doc , there is some sample code: var req = http.request(options, function(res)
On official Sencha downloads page - http://www.sencha.com/products/extjs/download/ those versions are between v 3.3 and
I have seen the official demos on lwjgl.org but I would like to see
I've been reading Boost Asio 's Tutorials (Official website). But I found them a
official android dev website says that:「You can implement your tab content in one of
So this is official Boost PropertyTree example , I try to compile it on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.