The basic_waitable_timer template uses wait traits to allow programs to customize wait and async_wait behavior. [ Note: Possible uses of wait traits include:
To enable timers based on non-realtime clocks.
Determining how quickly wallclock-based timers respond to system time changes.
Correcting for errors or rounding timeouts to boundaries.
Preventing duration overflow. That is, a program can set a timer's expiry e to be Clock::max() (meaning never reached) or Clock::min() (meaning always in the past). As a result, computing the duration until timer expiry as e - Clock::now() can cause overflow.
— end note ]
For a type Clock meeting the Clock requirements (C++ 2014 [time.clock.req]), a type X meets the WaitTraits requirements if it satisfies the requirements listed below.
In Table [tab:timer.reqmts.waittraits.requirements], t denotes a (possibly const) value of type Clock::time_point; and d denotes a (possibly const) value of type Clock::duration.
expression | return type | assertion/note pre/post-condition |
X::to_wait_duration(d) | Clock::duration | Returns a Clock::duration value to be used in a wait or async_wait operation. [ Note: The return value is typically representative of the duration d. — end note ] |
X::to_wait_duration(t) | Clock::duration | Returns a Clock::duration value to be used in a wait or async_wait operation. [ Note: The return value is typically representative of the duration from Clock::now() until the time point t. — end note ] |