A simulated TimeProvider
suitable for testing APIs which use Timer
.
More...
#include <simulated_time_provider.h>
Public Member Functions | |
SimulatedTimeProvider (typename Clock::time_point timestamp=typename Clock::time_point(typename Clock::duration(0))) | |
void | AdvanceTime (typename Clock::duration duration) |
Advances the simulated time and runs any newly-expired timers. | |
bool | AdvanceUntilNextExpiration () |
void | SetTime (typename Clock::time_point new_now) |
void | RunExpiredTimers () |
Clock::time_point | now () final |
Returns the current time. | |
std::optional< typename Clock::time_point > | NextExpiration () |
std::optional< typename Clock::duration > | TimeUntilNextExpiration () |
![]() | |
Clock::time_point | now () override=0 |
Returns the current time. | |
TimeFuture< Clock > | WaitFor (typename Clock::duration delay) |
TimeFuture< Clock > | WaitUntil (typename Clock::time_point timestamp) |
virtual Clock::time_point | now ()=0 |
Returns the current time. | |
Private Member Functions | |
void | DoInvokeAt (typename Clock::time_point wake_time) final |
void | DoCancel () final |
Optimistically cancels all pending DoInvokeAt requests. | |
Additional Inherited Members | |
![]() | |
void | RunExpired (typename Clock::time_point now) |
A simulated TimeProvider
suitable for testing APIs which use Timer
.
|
inline |
Advances the simulated time until the next point at which a timer would fire.
Returns whether any timers were waiting to be run.
|
inlinefinalprivatevirtual |
Optimistically cancels all pending DoInvokeAt
requests.
Implements pw::async2::TimeProvider< Clock >.
|
inlinefinalprivatevirtual |
Schedule RunExpired
to be invoked at time_point
. Newer calls to DoInvokeAt
supersede previous calls.
Implements pw::async2::TimeProvider< Clock >.
|
inlinefinalvirtual |
Returns the current time.
Implements pw::async2::TimeProvider< Clock >.
|
inline |
Explicitly run expired timers.
Calls to this function are not usually necessary, as AdvanceTime
and SetTime
will trigger expired timers to run. However, if a timer is set for a time in the past and neither AdvanceTime
nor SetTime
are subsequently invoked, the timer will not have a chance to run until one of AdvanceTime
, SetTime
, or RunExpiredTimers
has been called.
|
inline |
Modifies the simulated time and runs any newly-expired timers.
WARNING: Use of this function with a timestamp older than the current now()
will violate the is_monotonic clock attribute. We don't like it when time goes backwards!