VirtualClock (GenServerVirtualTime v0.1.0)
View SourceA GenServer that manages virtual time for testing time-dependent behaviors.
The VirtualClock maintains a virtual timestamp and scheduled events. Time can be advanced manually, triggering all events scheduled up to that point.
Example
iex> {:ok, clock} = VirtualClock.start_link()
iex> VirtualClock.now(clock)
0
iex> VirtualClock.advance(clock, 1000)
{:ok, 1000}
iex> VirtualClock.now(clock)
1000
Summary
Functions
Advances the virtual clock by the specified amount. All events scheduled up to the new time will be triggered.
Advances the virtual clock to the next scheduled event. Returns the time advanced, or 0 if no events are scheduled.
Cancels a scheduled timer.
Returns a specification to start this module under a supervisor.
Gets the current virtual time.
Returns the number of events currently scheduled.
Schedules a message to be sent after a delay in virtual time. Returns a reference that can be used to cancel the timer.
Starts a new virtual clock.
Functions
Advances the virtual clock by the specified amount. All events scheduled up to the new time will be triggered.
This advances time incrementally, processing each scheduled event and allowing new events to be scheduled in response.
Advances the virtual clock to the next scheduled event. Returns the time advanced, or 0 if no events are scheduled.
Cancels a scheduled timer.
Returns a specification to start this module under a supervisor.
See Supervisor.
Gets the current virtual time.
Returns the number of events currently scheduled.
Schedules a message to be sent after a delay in virtual time. Returns a reference that can be used to cancel the timer.
Starts a new virtual clock.