Class
SchedulerBuilder
View sourceCollects build-time configuration for normal and cross-world schedules, callback groups, and callbacks.
The builder stores this configuration until it is pushed to a
Scheduler, where it becomes runtime schedules and executables.
Examples
import { Scheduler, SchedulerBuilder } from '@wimaengine/schedule'
class Update {}
class MainWorld {}
function update(world) {
console.log('update', world)
}
const builder = new SchedulerBuilder()
builder.addSchedule({ label: Update, world: MainWorld })
builder.add({ schedule: Update, system: update })
const scheduler = new Scheduler()
builder.pushToScheduler(scheduler)Constructor
Properties
staticInstance: SchedulerBuilder
View sourceShared builder instance for code that uses the engine’s singleton build configuration.
Clear it before starting a new independent build with
SchedulerBuilder#clear.
Default: ...
Methods
clear(): SchedulerBuilder
View sourceClears queued configuration and derived schedule contexts.
This replaces all normal and cross-world config arrays and context maps
with empty collections. It does not modify a Scheduler previously
passed to SchedulerBuilder#pushToScheduler. Call this before
reusing a builder for a new build; pushing does not clear the builder.
Examples
import { SchedulerBuilder } from '@wimaengine/schedule'
const builder = new SchedulerBuilder()
builder.addSchedule({ label: class Update {} })
const sameBuilder = builder.clear()
sameBuilder === builder // trueaddSchedule(config: ScheduleConfig): void
View sourceQueues a normal schedule for the next build push.
The config is stored as provided. It does not validate the target world or
register an executable immediately. During
SchedulerBuilder#pushToScheduler, the explicit world, or
defaultWorld when world is absent, is checked before a
Schedule executable is registered with the target
Scheduler.
Examples
import { SchedulerBuilder } from '@wimaengine/schedule'
class Update {}
class MainWorld {}
const builder = new SchedulerBuilder()
builder.addSchedule({ label: Update, world: MainWorld })
// The executable is created when builder.pushToScheduler(...) runs.addCrossWorldSchedule(config: CrossWorldScheduleConfig): void
View sourceQueues a cross-world schedule for the next build push.
The config is stored as provided. It does not validate the worlds or
register an executable immediately. During
SchedulerBuilder#pushToScheduler, the target world uses
defaultWorld only when the config has no world, and sourceWorld is
required before a CrossWorldSchedule executable is registered.
Examples
import { SchedulerBuilder } from '@wimaengine/schedule'
class Synchronize {}
class MainWorld {}
class SourceWorld {}
const builder = new SchedulerBuilder()
builder.addCrossWorldSchedule({
label: Synchronize,
world: MainWorld,
sourceWorld: SourceWorld
})
// Registration is deferred until builder.pushToScheduler(...).add(config: object): void
View sourceQueues a normal callback for the next build push.
The config remains in the builder until
SchedulerBuilder#createScheduleContexts assigns it to a
ScheduleContext. Registration and ordering validation are
deferred until SchedulerBuilder#pushToScheduler.
addCrossworldSystem(config: object): void
View sourceQueues a cross-world callback for the next build push.
The config remains in the builder until
SchedulerBuilder#createCrossWorldScheduleContexts assigns it to a
CrossWorldScheduleContext. Label and ordering validation are
deferred until the context is built and sorted.
addGroup(config: object): void
View sourceQueues a normal callback-group configuration for the next build push.
The group is not registered immediately. During context creation,
ScheduleContext validates its label, parent relationship, and
ordering references.
pushToScheduler(scheduler: Scheduler, defaultWorld: ConstructorFn): void
View sourceBuilds the collected configuration into a runtime scheduler.
Each queued normal schedule creates an Executable with a new
Schedule and registers it with Scheduler#set. Each
queued cross-world schedule creates an executable with a new
CrossWorldSchedule and registers it with
Scheduler#setCrossWorld. The executable constructor supplies
defaults for omitted options such as repeat and delay.
For both schedule kinds, config.world takes precedence over
defaultWorld; a target world is checked before the executable is
created. Cross-world configs also require config.sourceWorld; there is
no source-world fallback. Missing worlds throw before callback contexts
are built.
Callback-group and callback configs are then collected into
ScheduleContext instances. The last queued defaultSystemGroup
for a schedule type ID is used as the context’s fallback group. Group
parents and assignments are resolved before ordered callbacks are added to
the matching schedule from Scheduler#get. Cross-world callbacks
are collected into CrossWorldScheduleContext instances and added
in resolved order to schedules from Scheduler#getCrossWorld.
Each required runtime schedule must exist in scheduler.
This method does not clear queued configuration or derived contexts; call
SchedulerBuilder#clear before collecting a new build.
