![]() |
BRICKS
Small, useful blocks of code, to build bigger things.
|
A timer that can be started and aborted. More...
#include <timer.hpp>
Public Types | |
using | completion_token = std::future<void> |
A completion token that can be used to wait for the timer to complete. | |
Public Member Functions | |
timer () noexcept | |
Default constructor. | |
timer (const timer &)=delete | |
A timer cannot be copied. | |
auto | operator= (const timer &) -> timer &=delete |
A timer cannot be copied. | |
timer (timer &&)=default | |
Move constructor. | |
auto | operator= (timer &&) -> timer &=default |
Move assignment operator. | |
~timer () | |
Destroy the timer object. | |
template<typename Rep = int64_t, typename Period = std::ratio<1>> | |
auto | start (const std::chrono::duration< Rep, Period > &duration=std::chrono::duration< Rep, Period >{}) const noexcept -> completion_token |
Starts the timer, returning a completion token that will be completed when the timer expires. | |
auto | abort () -> void |
Aborts the timer. | |
A timer that can be started and aborted.
The timer can be started with a duration. If the timer is not aborted, the completion token returned by start
will be ready after the duration has passed. If the timer is aborted, the completion token will be ready immediately. Will abort all outstanding timers when it is destroyed.
Example:
using bricks::timer::completion_token = std::future<void> |
A completion token that can be used to wait for the timer to complete.
The completion token can be used to wait for the timer to complete. If the timer is not aborted, the completion token will be ready after the duration has passed. If the timer is aborted, the completion token will be ready immediately.
Example:
|
inlinenoexcept |
Default constructor.
|
delete |
A timer cannot be copied.
|
default |
Move constructor.
|
inline |
Destroy the timer object.
Will abort all outstanding timers.
|
inline |
Aborts the timer.
This function aborts the timer, causing any completion tokens returned by start
to complete.
Example:
|
inlinenodiscardnoexcept |
Starts the timer, returning a completion token that will be completed when the timer expires.
Example:
duration | The duration to wait before completing the token. |