|
| basic_waitable_timer (const executor_type &ex) |
| Constructor. More...
|
|
template<typename ExecutionContext > |
| basic_waitable_timer (ExecutionContext &context, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0) |
| Constructor. More...
|
|
| basic_waitable_timer (const executor_type &ex, const time_point &expiry_time) |
| Constructor to set a particular expiry time as an absolute time. More...
|
|
template<typename ExecutionContext > |
| basic_waitable_timer (ExecutionContext &context, const time_point &expiry_time, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0) |
| Constructor to set a particular expiry time as an absolute time. More...
|
|
| basic_waitable_timer (const executor_type &ex, const duration &expiry_time) |
| Constructor to set a particular expiry time relative to now. More...
|
|
template<typename ExecutionContext > |
| basic_waitable_timer (ExecutionContext &context, const duration &expiry_time, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0) |
| Constructor to set a particular expiry time relative to now. More...
|
|
| ~basic_waitable_timer () |
| Destroys the timer. More...
|
|
executor_type | get_executor () ASIO_NOEXCEPT |
| Get the executor associated with the object.
|
|
std::size_t | cancel () |
| Cancel any asynchronous operations that are waiting on the timer. More...
|
|
std::size_t | cancel (asio::error_code &ec) |
| (Deprecated: Use non-error_code overload.) Cancel any asynchronous operations that are waiting on the timer. More...
|
|
std::size_t | cancel_one () |
| Cancels one asynchronous operation that is waiting on the timer. More...
|
|
std::size_t | cancel_one (asio::error_code &ec) |
| (Deprecated: Use non-error_code overload.) Cancels one asynchronous operation that is waiting on the timer. More...
|
|
time_point | expires_at () const |
| (Deprecated: Use expiry().) Get the timer's expiry time as an absolute time. More...
|
|
time_point | expiry () const |
| Get the timer's expiry time as an absolute time. More...
|
|
std::size_t | expires_at (const time_point &expiry_time) |
| Set the timer's expiry time as an absolute time. More...
|
|
std::size_t | expires_at (const time_point &expiry_time, asio::error_code &ec) |
| (Deprecated: Use non-error_code overload.) Set the timer's expiry time as an absolute time. More...
|
|
std::size_t | expires_after (const duration &expiry_time) |
| Set the timer's expiry time relative to now. More...
|
|
duration | expires_from_now () const |
| (Deprecated: Use expiry().) Get the timer's expiry time relative to now. More...
|
|
std::size_t | expires_from_now (const duration &expiry_time) |
| (Deprecated: Use expires_after().) Set the timer's expiry time relative to now. More...
|
|
std::size_t | expires_from_now (const duration &expiry_time, asio::error_code &ec) |
| (Deprecated: Use expires_after().) Set the timer's expiry time relative to now. More...
|
|
void | wait () |
| Perform a blocking wait on the timer. More...
|
|
void | wait (asio::error_code &ec) |
| Perform a blocking wait on the timer. More...
|
|
template<WaitHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE> |
| ASIO_INITFN_AUTO_RESULT_TYPE (WaitHandler, void(asio::error_code)) async_wait(ASIO_MOVE_ARG(WaitHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)) |
| Start an asynchronous wait on the timer. More...
|
|
template<typename Clock, typename WaitTraits, typename Executor>
class asio::basic_waitable_timer< Clock, WaitTraits, Executor >
Provides waitable timer functionality.
The basic_waitable_timer class template provides the ability to perform a blocking or asynchronous wait for a timer to expire.
A waitable timer is always in one of two states: "expired" or "not expired". If the wait() or async_wait() function is called on an expired timer, the wait operation will complete immediately.
Most applications will use one of the asio::steady_timer, asio::system_timer or asio::high_resolution_timer typedefs.
- Note
- This waitable timer functionality is for use with the C++11 standard library's
<chrono>
facility, or with the Boost.Chrono library.
- Thread Safety
- Distinct objects: Safe.
Shared objects: Unsafe.
- Examples
- Performing a blocking wait (C++11):
asio::steady_timer timer(my_context);
timer.expires_after(std::chrono::seconds(5));
timer.wait();
- Performing an asynchronous wait (C++11):
{
if (!error)
{
}
}
...
asio::steady_timer timer(my_context,
std::chrono::steady_clock::now() + std::chrono::seconds(60));
timer.async_wait(handler);
- Changing an active waitable 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_after(seconds(5)) > 0)
{
my_timer.async_wait(on_timeout);
}
else
{
}
}
{
if (e != asio::error::operation_aborted)
{
}
}
- The asio::basic_waitable_timer::expires_after() function cancels any pending asynchronous waits, and returns the number of asynchronous waits that were cancelled. If it returns 0 then you were too late and the wait handler has already been executed, or will soon be executed. If it returns 1 then the wait handler was successfully cancelled.
- If a wait handler is cancelled, the asio::error_code passed to it contains the value asio::error::operation_aborted.
template<typename Clock , typename WaitTraits , typename Executor >
template<WaitHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE>
Start an asynchronous wait on the timer.
This function may be used to initiate an asynchronous wait against the timer. It always returns immediately.
For each call to async_wait(), the supplied handler will be called exactly once. The handler will be called when:
- The timer was cancelled, in which case the handler is passed the error code asio::error::operation_aborted.
- Parameters
-
handler | The handler to be called when the timer expires. Copies will be made of the handler as required. The function signature of the handler must be: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::post(). |
template<typename Clock , typename WaitTraits , typename Executor >
Cancel any asynchronous operations that are waiting on the timer.
This function forces the completion of any pending asynchronous wait operations against the timer. The handler for each cancelled operation will be invoked with the asio::error::operation_aborted error code.
Cancelling the timer does not change the expiry time.
- Returns
- The number of asynchronous operations that were cancelled.
- Exceptions
-
- Note
- If the timer has already expired when cancel() is called, then the handlers for asynchronous wait operations will:
- have already been invoked; or
- have been queued for invocation in the near future.
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
template<typename Clock , typename WaitTraits , typename Executor >
(Deprecated: Use non-error_code overload.) Cancel any asynchronous operations that are waiting on the timer.
This function forces the completion of any pending asynchronous wait operations against the timer. The handler for each cancelled operation will be invoked with the asio::error::operation_aborted error code.
Cancelling the timer does not change the expiry time.
- Parameters
-
ec | Set to indicate what error occurred, if any. |
- Returns
- The number of asynchronous operations that were cancelled.
- Note
- If the timer has already expired when cancel() is called, then the handlers for asynchronous wait operations will:
- have already been invoked; or
- have been queued for invocation in the near future.
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
template<typename Clock , typename WaitTraits , typename Executor >
Cancels one asynchronous operation that is waiting on the timer.
This function forces the completion of one pending asynchronous wait operation against the timer. Handlers are cancelled in FIFO order. The handler for the cancelled operation will be invoked with the asio::error::operation_aborted error code.
Cancelling the timer does not change the expiry time.
- Returns
- The number of asynchronous operations that were cancelled. That is, either 0 or 1.
- Exceptions
-
- Note
- If the timer has already expired when cancel_one() is called, then the handlers for asynchronous wait operations will:
- have already been invoked; or
- have been queued for invocation in the near future.
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
template<typename Clock , typename WaitTraits , typename Executor >
(Deprecated: Use non-error_code overload.) Cancels one asynchronous operation that is waiting on the timer.
This function forces the completion of one pending asynchronous wait operation against the timer. Handlers are cancelled in FIFO order. The handler for the cancelled operation will be invoked with the asio::error::operation_aborted error code.
Cancelling the timer does not change the expiry time.
- Parameters
-
ec | Set to indicate what error occurred, if any. |
- Returns
- The number of asynchronous operations that were cancelled. That is, either 0 or 1.
- Note
- If the timer has already expired when cancel_one() is called, then the handlers for asynchronous wait operations will:
- have already been invoked; or
- have been queued for invocation in the near future.
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
template<typename Clock , typename WaitTraits , typename Executor >
Set the timer's expiry time relative to now.
This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the asio::error::operation_aborted error code.
- Parameters
-
expiry_time | The expiry time to be used for the timer. |
- Returns
- The number of asynchronous operations that were cancelled.
- Exceptions
-
- Note
- If the timer has already expired when expires_after() is called, then the handlers for asynchronous wait operations will:
- have already been invoked; or
- have been queued for invocation in the near future.
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
template<typename Clock , typename WaitTraits , typename Executor >
Set the timer's expiry time as an absolute time.
This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the asio::error::operation_aborted error code.
- Parameters
-
expiry_time | The expiry time to be used for the timer. |
- Returns
- The number of asynchronous operations that were cancelled.
- Exceptions
-
- Note
- If the timer has already expired when expires_at() is called, then the handlers for asynchronous wait operations will:
- have already been invoked; or
- have been queued for invocation in the near future.
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
template<typename Clock , typename WaitTraits , typename Executor >
(Deprecated: Use non-error_code overload.) Set the timer's expiry time as an absolute time.
This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the asio::error::operation_aborted error code.
- Parameters
-
expiry_time | The expiry time to be used for the timer. |
ec | Set to indicate what error occurred, if any. |
- Returns
- The number of asynchronous operations that were cancelled.
- Note
- If the timer has already expired when expires_at() is called, then the handlers for asynchronous wait operations will:
- have already been invoked; or
- have been queued for invocation in the near future.
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
template<typename Clock , typename WaitTraits , typename Executor >
(Deprecated: Use expires_after().) Set the timer's expiry time relative to now.
This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the asio::error::operation_aborted error code.
- Parameters
-
expiry_time | The expiry time to be used for the timer. |
- Returns
- The number of asynchronous operations that were cancelled.
- Exceptions
-
- Note
- If the timer has already expired when expires_from_now() is called, then the handlers for asynchronous wait operations will:
- have already been invoked; or
- have been queued for invocation in the near future.
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
template<typename Clock , typename WaitTraits , typename Executor >
(Deprecated: Use expires_after().) Set the timer's expiry time relative to now.
This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the asio::error::operation_aborted error code.
- Parameters
-
expiry_time | The expiry time to be used for the timer. |
ec | Set to indicate what error occurred, if any. |
- Returns
- The number of asynchronous operations that were cancelled.
- Note
- If the timer has already expired when expires_from_now() is called, then the handlers for asynchronous wait operations will:
- have already been invoked; or
- have been queued for invocation in the near future.
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.