Pigweed
 
Loading...
Searching...
No Matches
pw::async2::SimulatedTimeProvider< Clock > Class Template Referencefinal

A simulated TimeProvider suitable for testing APIs which use Timer. More...

#include <simulated_time_provider.h>

Inheritance diagram for pw::async2::SimulatedTimeProvider< Clock >:
pw::async2::TimeProvider< Clock > pw::chrono::VirtualClock< Clock >

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 ()
 
- Public Member Functions inherited from pw::async2::TimeProvider< Clock >
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

- Protected Member Functions inherited from pw::async2::TimeProvider< Clock >
void RunExpired (typename Clock::time_point now)
 

Detailed Description

template<typename Clock>
class pw::async2::SimulatedTimeProvider< Clock >

A simulated TimeProvider suitable for testing APIs which use Timer.

Member Function Documentation

◆ AdvanceUntilNextExpiration()

template<typename Clock >
bool pw::async2::SimulatedTimeProvider< Clock >::AdvanceUntilNextExpiration ( )
inline

Advances the simulated time until the next point at which a timer would fire.

Returns whether any timers were waiting to be run.

◆ DoCancel()

template<typename Clock >
void pw::async2::SimulatedTimeProvider< Clock >::DoCancel ( )
inlinefinalprivatevirtual

Optimistically cancels all pending DoInvokeAt requests.

Implements pw::async2::TimeProvider< Clock >.

◆ DoInvokeAt()

template<typename Clock >
void pw::async2::SimulatedTimeProvider< Clock >::DoInvokeAt ( typename Clock::time_point  )
inlinefinalprivatevirtual

Schedule RunExpired to be invoked at time_point. Newer calls to DoInvokeAt supersede previous calls.

Implements pw::async2::TimeProvider< Clock >.

◆ now()

template<typename Clock >
Clock::time_point pw::async2::SimulatedTimeProvider< Clock >::now ( )
inlinefinalvirtual

Returns the current time.

Implements pw::async2::TimeProvider< Clock >.

◆ RunExpiredTimers()

template<typename Clock >
void pw::async2::SimulatedTimeProvider< Clock >::RunExpiredTimers ( )
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.

◆ SetTime()

template<typename Clock >
void pw::async2::SimulatedTimeProvider< Clock >::SetTime ( typename Clock::time_point  new_now)
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!


The documentation for this class was generated from the following file: