[/
 / Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 /
 / Distributed under the Boost Software License, Version 1.0. (See accompanying
 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 /]

[section:timers Timers]

Long running I/O operations will often have a deadline by which they must have
completed. These deadlines may be expressed as absolute times, but are often
calculated relative to the current time.

As a simple example, to perform a synchronous wait operation on a timer using a
relative time one may write:

  io_context i;
  ...
  steady_timer t(i);
  t.expires_after(chrono::seconds(5));
  t.wait();

More commonly, a program will perform an asynchronous wait operation on a
timer:

  void handler(asio::error_code ec) { ... }
  ...
  io_context i;
  ...
  steady_timer t(i);
  t.expires_after(chrono::milliseconds(400));
  t.async_wait(handler);
  ...
  i.run();

The deadline associated with a timer may also be obtained as an absolute time:

  steady_timer::time_point time_of_expiry = t.expiry();

which allows composition of timers:

  steady_timer t2(i);
  t2.expires_at(t.expiry() + chrono::seconds(30));

[heading See Also]

[link asio.reference.basic_waitable_timer basic_waitable_timer],
[link asio.reference.steady_timer steady_timer],
[link asio.reference.system_timer system_timer],
[link asio.reference.high_resolution_timer high_resolution_timer],
[link asio.tutorial.tuttimer1 timer tutorials].

[endsect]
