API Reference
Gears.MachineClock — Type
MachineClockA clock that uses the system time. The time is represented in seconds. Supports pausing and resuming to decouple logical time from system time. The start_time, pause_start_time, and total_paused_time are all represented in seconds and are wall clock (unstretched) time. Whenever now is called, the time is stretched by the stretch_factor. This means that when the stretch_factor is greater than 1, the time will progress faster than the wall clock time.
Fields
start_time::T: The system time when the clock was created or last resetpaused::Bool: Whether the clock is currently pausedtotal_paused_time::T: Cumulative time spent pausedpause_start_time::Union{T, Nothing}: System time when current pause started (if any)stretch_factor::F: The factor by which to stretch the time
Gears.TickedScheduler — Type
TickedScheduler{C <: Clock, T} <: SchedulerA scheduler that processes jobs at regular tick intervals.
Fields
clock::C: The clock providing time informationjobs::Vector{Job}: The jobs to be scheduledticker::Ticker{T}: The ticker that manages timing
Gears.TickedScheduler — Method
TickedScheduler(clock::Clock, tick_period::T) where {T}Create a new TickedScheduler with the specified clock and tick period.
Gears.Ticker — Type
Ticker{T}A mutable struct that handles time accumulation and tick processing.
Fields
period::T: The fixed tick periodlast_tick_time::T: The time when the last tick was processedaccumulated_lag::T: Unprocessed time since the last tick
Gears.Ticker — Method
Ticker(period::Quantity{T, 𝐓}) where {T}Create a new Ticker with the specified tick period.
Gears.TimedJob — Type
TimedJob{F, T}A job that executes at regular time intervals.
Fields
f::F: The function to executeticker::Ticker{T}: The ticker that manages timing
Gears.TimedJob — Method
TimedJob(f, period::Quantity{T, 𝐓}) where {T}Create a new TimedJob with the specified function and tick period.
Gears.VirtualClock — Type
VirtualClockA clock that uses virtual time for simulations. The time is represented in seconds.
Fields
current_time::T: The current time of the clock
This clock can be advanced with the advance_time! function.
Gears.advance_time! — Method
advance_time!(clock::VirtualClock{T}, dt::Quantity{<:Number, 𝐓})Advance the time of the clock by a given duration. Uses Unitful.jl for time units.
Gears.advance_to! — Method
advance_to!(ticker::Ticker, absolute_time::Quantity{<:Number, 𝐓})Advance the ticker to an absolute time, updating internal state accordingly.
Gears.can_tick — Method
can_tick(ticker::Ticker)Check if the ticker has accumulated enough time to process a tick.
Gears.consume_tick! — Method
consume_tick!(ticker::Ticker)Consume one tick, reducing the accumulated lag by the tick period.
Gears.global_clock — Method
global_clock()Returns the global clock instance.
Note: This function is type-unstable but the type instability is isolated by function barriers in the calling code.
Gears.global_scheduler — Method
global_scheduler()Returns the global scheduler instance.
Note: This function is type-unstable but the type instability is isolated by function barriers in the calling code.
Gears.pause! — Method
pause!(clock::MachineClock)Pause the clock. While paused, logical time stops progressing.
Gears.progress! — Method
progress!(job::Job, t::Quantity{<:Number, 𝐓})Execute the job with the current time. The job decides internally whether to perform work.
Gears.progress! — Method
progress!(ticker::Ticker, delta_time::Quantity{<:Number, 𝐓})Progress the ticker by a delta time, updating internal state accordingly.
Gears.progress! — Method
progress!(job::TimedJob, dt::Quantity{<:Number, 𝐓})Progress the job by the specified time delta, executing the function for each available tick.
Gears.reset! — Method
reset!(ticker::Ticker, time::Quantity{<:Number, 𝐓})Reset the ticker to start at the specified time with no accumulated lag.
Gears.reset_global_clock! — Method
reset_global_clock!()Resets the global clock to the default MachineClock instance.
Gears.reset_global_scheduler! — Method
reset_global_scheduler!()Resets the global scheduler to the default TickedScheduler instance.
Gears.resume! — Method
resume!(clock::MachineClock)Resume the clock. Logical time continues from where it was paused.
Gears.schedule! — Method
schedule!(scheduler::Scheduler, job::Job)Register a job with the scheduler to run. Can be implemented for concrete types to define scheduling behavior for different schedulers and job types.
Gears.schedule! — Method
schedule!(scheduler::TickedScheduler, job::Job)Schedule a job to be executed by the scheduler.
Gears.set_global_clock! — Method
set_global_clock!(clock::Clock)Sets the global clock to the specified instance.
Arguments
clock::Clock: The clock instance to use globally
Gears.set_global_scheduler! — Method
set_global_scheduler!(scheduler::Scheduler)Sets the global scheduler to the specified instance.
Arguments
scheduler::Scheduler: The scheduler instance to use globally
Gears.set_time! — Method
set_time!(clock::VirtualClock{T}, time::Quantity{<:Number, 𝐓})Set the time of the clock. Uses Unitful.jl for time units.
Gears.update! — Method
update!(scheduler::Scheduler)Update the scheduler to the current time as provided with the associated clock. This distributes time to the scheduled jobs until virtual time has caught up with the current time provided by the clock (optionally also virtual).
Gears.update! — Method
update!(scheduler::TickedScheduler)Update the scheduler by advancing to the current time and processing available ticks.