Pigweed
C/C++ API Reference
|
Public Member Functions | |
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. | |
Protected Member Functions | |
void | RunExpired (typename Clock::time_point now) |
Private Member Functions | |
virtual void | DoInvokeAt (typename Clock::time_point)=0 |
virtual void | DoCancel ()=0 |
Optimistically cancels all pending DoInvokeAt requests. | |
Friends | |
class | TimeFuture< Clock > |
A factory for time and timers.
This extends the VirtualClock
interface with the ability to create async timers.
TimeProvider
is designed to be dependency-injection friendly so that code that uses time and timers is not bound to real wall-clock time. This is particularly helpful for testing timing-sensitive code without adding manual delays to tests (which often results in flakiness and long-running tests).
Note that Timer
objects must not outlive the TimeProvider
from which they were created.
|
privatepure virtual |
Optimistically cancels all pending DoInvokeAt
requests.
Implemented in pw::async2::SimulatedTimeProvider< Clock >.
|
privatepure virtual |
Schedule RunExpired
to be invoked at time_point
. Newer calls to DoInvokeAt
supersede previous calls.
Implemented in pw::async2::SimulatedTimeProvider< Clock >.
|
overridepure virtual |
Returns the current time.
Implements pw::chrono::VirtualClock< Clock >.
Implemented in pw::async2::SimulatedTimeProvider< Clock >.
|
protected |
Run all expired timers with the current (provided) time_point
.
This method should be invoked by subclasses when DoInvokeAt
's timer expires.
|
inline |
Queues the callback
to be invoked after delay
.
This method is thread-safe and can be invoked from callback
but may not be interrupt-safe on all platforms.
The time_point is computed based on now() plus the specified duration where a singular clock tick is added to handle partial ticks. This ensures that a duration of at least 1 tick does not result in [0,1] ticks and instead in [1,2] ticks.
|
inline |
Queues the callback
to be invoked after timestamp
.
This method is thread-safe and can be invoked from callback
but may not be interrupt-safe on all platforms.