Scheduler

View source

Maintains separate normal-world and cross-world registries. Each registry maps a schedule-label constructor to an Executable. Normal-world entries expose a Schedule; cross-world entries expose a CrossWorldSchedule with target and source worlds. Register entries with Scheduler#set or Scheduler#setCrossWorld, then retrieve their schedules with Scheduler#get or Scheduler#getCrossWorld.

Examples

import { CrossWorldSchedule, Executable, Scheduler } from '@wimaengine/schedule'

class Update {}
class Sync {}
class MainWorld {}
class SourceWorld {}

const scheduler = new Scheduler()
scheduler.set(new Executable({
  label: Update,
  world: MainWorld,
  sourceWorld: undefined
}))
scheduler.setCrossWorld(new Executable({
  label: Sync,
  world: MainWorld,
  sourceWorld: SourceWorld,
  schedule: new CrossWorldSchedule()
}))

scheduler.get(Update)?.add((world) => console.log('update', world))
scheduler.getCrossWorld(Sync)?.add((target, source) => {
  console.log('sync', target, source)
})

Constructor


constructor()

Methods


set(executable: Executable<Schedule, undefined>): void

View source

Registers an Executable in the normal-world registry.

The registry key is typeid(executable.label). Registering another executable with the same key replaces the previous entry. Its Schedule is returned by Scheduler#get for the same label.

Parameters

NameDescriptionDefault
executable——

values(): MapIterator<Executable<Schedule, undefined>>

View source

Returns the values iterator for the normal-world executable registry.

This is the iterator returned directly by this.executables.values(). It yields complete Executable records from the normal-world registry in Map insertion order. A new label registered through Scheduler#set is appended; replacing an existing label updates its record without moving that label’s position.

crossWorldValues(): MapIterator<Executable<CrossWorldSchedule, ConstructorFn>>

View source

Returns the values iterator for the cross-world executable registry.

This is the iterator returned directly by this.crossWorldExecutables.values(). It yields complete Executable records with cross-world schedules from the cross-world registry in Map insertion order. A new label registered through Scheduler#setCrossWorld is appended; replacing an existing label updates its record without moving that label’s position.