SchedulerBuilder

View source

Collects 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


constructor()

Properties


Methods


clear(): SchedulerBuilder

View source

Clears 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 // true

Returns

This builder after its state is reset.

addSchedule(config: ScheduleConfig): void

View source

Queues 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.

Parameters

NameDescriptionDefault
config

Schedule label and runtime options.

—

addCrossWorldSchedule(config: CrossWorldScheduleConfig): void

View source

Queues 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(...).

Parameters

NameDescriptionDefault
config

Cross-world schedule label, worlds, and runtime options.

—

addGroup(config: object): void

View source

Queues 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.

Parameters

NameDescriptionDefault
config

Group label, schedule, parent, and ordering options.

—

pushToScheduler(scheduler: Scheduler, defaultWorld: ConstructorFn): void

View source

Builds 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.

Parameters

NameDescriptionDefault
scheduler

Runtime scheduler receiving executables and callbacks.

—
defaultWorld

Fallback target-world label for configs without a world.

—

Throws

If a required world or runtime schedule is missing, or if context validation or ordering fails.