Schedulers

Overview

Schedulers distribute time to jobs and manage when jobs should be executed, coordinating between the clock and the jobs. They can be configured to run in a single thread or in multiple threads.

Scheduler Interface

All schedulers implement the Scheduler abstract type and must provide:

schedule!(scheduler::Scheduler, job::Job)
update!(scheduler::Scheduler)
Gears.schedule!Function
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.

source
schedule!(scheduler::TickedScheduler, job::Job)

Schedule a job to be executed by the scheduler.

source
Gears.update!Function
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).

source
update!(scheduler::TickedScheduler)

Update the scheduler by advancing to the current time and processing available ticks.

source

Implementations

TickedScheduler

Discretizes time into ticks and executes jobs within each tick. Provides deterministic execution timing.

Usage Examples

clock = VirtualClock()
scheduler = TickedScheduler(clock, 10ms)

# Schedule jobs
every(scheduler, 30ms) do dt
    println("Timed job: $(now(clock))")
end

# Run scheduler
for_next(clock, 100ms) do
    update!(scheduler)
    advance_time!(clock, 10ms)
end