16namespace golxzn::os::chrono {
59template<
class OnTimerDone,
class BaseClock = utils::default_base_clock>
61 static_assert(BaseClock::is_steady,
62 "[golxzn::os::chrono::timer] BaseClock is not a monotonic clock");
63 static_assert(utils::enough_resolution_v<BaseClock>,
64 "[golxzn::os::chrono::timer] BaseClock's resolution is less than microseconds!");
65 static_assert(std::is_invocable_v<OnTimerDone>,
66 "[golxzn::os::chrono::timer] OnTimerDone is not invocable!");
82 template<
class Rep,
class Period>
84#
if defined(GOLXZN_MULTITHREADING)
85 ,
const std::chrono::microseconds precision = constants::default_precision
99#
if defined(GOLXZN_MULTITHREADING)
100 ,
const std::chrono::microseconds precision = constants::default_precision
104#if defined(GOLXZN_MULTITHREADING)
108#if !defined(GOLXZN_MULTITHREADING)
139 const
time_point m_start_time{ base_clock::now() };
142#if defined(GOLXZN_MULTITHREADING)
143 std::thread m_timer_thread;
168template<
class BaseClock = utils::default_base_clock>
170 static_assert(BaseClock::is_steady,
171 "[golxzn::os::chrono::fast_timer] BaseClock is not a monotonic clock");
172 static_assert(utils::enough_resolution_v<BaseClock>,
173 "[golxzn::os::chrono::fast_timer] BaseClock's resolution is less than microseconds!");
204 template<
class Rep,
class Period>
205 explicit constexpr fast_timer(
const std::chrono::duration<Rep, Period> timer_interval)
noexcept;
212 [[nodiscard]]
constexpr bool is_done() const noexcept;
229 const
time_point m_start_time{ base_clock::now() };
233#include "golxzn/os/chrono/impl/timer.inl"
Class that represents fast_timer.
Definition timer.hpp:169
constexpr fast_timer(const time timer_interval) noexcept
fast_timer constructor from timer interval.
constexpr time time_left() const noexcept
Returns time left to the end of the timer.
constexpr bool is_running() const noexcept
Returns true if timer is running.
constexpr fast_timer(const time_point timer_interval) noexcept
fast_timer constructor from timer interval.
constexpr fast_timer(const std::chrono::duration< Rep, Period > timer_interval) noexcept
fast_timer constructor from timer interval.
BaseClock base_clock
Base clock type.
Definition timer.hpp:176
constexpr bool is_done() const noexcept
Returns true if timer is done.
typename base_clock::time_point time_point
Type of time point from base_clock.
Definition timer.hpp:177
Class that represents time.
Definition time.hpp:30
Class that represents timer.
Definition timer.hpp:60
timer(const time timer_interval, timer_end_callback &&callback)
Timer constructor from timer interval and callback.
BaseClock base_clock
Base clock type.
Definition timer.hpp:69
time time_left() const noexcept
Returns time left to the end of the timer.
bool is_running() const noexcept
Returns true if timer is running.
bool is_done() const noexcept
Returns true if timer is done.
OnTimerDone timer_end_callback
Type of callback that will be called when timer is done.
Definition timer.hpp:71
timer(const std::chrono::duration< Rep, Period > timer_interval, timer_end_callback &&callback)
Timer constructor from timer interval and callback.
typename base_clock::time_point time_point
Type of time point from base_clock.
Definition timer.hpp:70
void update()
Updates timer. (only when GOLXZN_MULTITHREADING is not defined)
Class that represents time.
static constexpr std::chrono::microseconds default_precision
Default precision of timer. Only if GOLXZN_MULTITHREADING is defined. This value is used as time to ...
Definition timer.hpp:30