constructor(label: ConstructorFn)
View sourceCreates build state for a cross-world schedule label.
Class
Collects cross-world callback registrations and ordering rules for one schedule label.
SchedulerBuilder uses this context to order callbacks before
populating the runtime CrossWorldSchedule.
import { CrossWorldScheduleContext } from '@wimaengine/schedule'
class Synchronize {}
function copy(target, source) {}
function flush(target, source) {}
const context = new CrossWorldScheduleContext(Synchronize)
context.addSystem({ schedule: Synchronize, system: copy })
context.addSystem({ schedule: Synchronize, after: [copy], system: flush })
const orderedSystems = context.sortSystems()constructor(label: ConstructorFn)Creates build state for a cross-world schedule label.
Schedule constructor used to identify this build context.
Cross-world callbacks registered for this schedule, in registration order.
Each registration receives a zero-based ID equal to its position when it
is added. The builder later uses the ordered registrations to populate the
matching CrossWorldSchedule.
Default: []
Maps non-empty callback labels to ordering-node references.
CrossWorldScheduleContext#addSystem resolves a label from
config.label or config.system.name; ordering references are looked up
here before graph edges are added.
Default: ...
addSystem(config: object): CrossWorldSystemRegistrationRegisters a cross-world callback in this context.
The returned registration receives the next zero-based ID. A truthy
config.label, or the callback function’s name when it is absent or empty,
becomes the ordering label. A non-empty label is registered for before
and after references. Duplicate non-empty labels are rejected
immediately. Ordering references are stored in config and resolved later
by CrossWorldScheduleContext#sortSystems.
import { CrossWorldScheduleContext } from '@wimaengine/schedule'
class Synchronize {}
function copy(target, source) {}
function flush(target, source) {}
const context = new CrossWorldScheduleContext(Synchronize)
context.addSystem({ schedule: Synchronize, system: copy })
context.addSystem({ schedule: Synchronize, after: [copy], system: flush })sortSystems(): CrossWorldSystemRegistration[]Resolves ordering constraints and returns callbacks in execution order.
The context expands each registered callback and its before/after
references into a directed graph, then applies a topological sort. The
returned array contains callback registrations only. Cross-world contexts
do not expand callback groups.
Missing labels and self-referential edges are rejected while the graph is expanded. If the resolved graph contains a cycle, this method throws instead of returning a partial order.
expandScheduleGraph(): objectExpands registered callbacks and ordering constraints into a directed graph.
One graph node is created for each callback, and systemsByGraphId maps
graph nodes back to their registrations. Each before reference adds an
edge from the current callback to the referenced callback; each after
reference adds the reverse edge. Duplicate edges are ignored. This method
builds the graph but does not sort it; use
CrossWorldScheduleContext#sortSystems for the ordered registrations.
addNodeOrdering(graph: Graph<CrossWorldSystemRegistration, undefined>, graphIdsBySystemId: Map<number, number>, edges: Set<string>, source: ScheduleNodeRef, before: CrossWorldSystemOrderReference[], after: CrossWorldSystemOrderReference[]): voidAdds graph edges for one callback’s ordering constraints.
Each before reference creates an edge from source to the referenced
callback. Each after reference creates an edge from the referenced
callback to source. References are converted to labels and resolved
through CrossWorldScheduleContext#resolveNode; duplicate edges
are ignored by CrossWorldScheduleContext#addExpandedEdge.
resolveNode(label: string): ScheduleNodeRefaddExpandedEdge(graph: Graph<CrossWorldSystemRegistration, undefined>, graphIdsBySystemId: Map<number, number>, edges: Set<string>, from: ScheduleNodeRef, to: ScheduleNodeRef, targetLabel: CrossWorldSystemOrderReference): voidAdds one directed graph edge between two registered callbacks.
The endpoint registrations are converted to graph node IDs. An edge that has already been added is ignored. An edge whose endpoints are the same callback is rejected because it creates a self-referential ordering.
expandNodeToOrderingNode(node: ScheduleNodeRef, graphIdsBySystemId: Map<number, number>): numberResolves a registered callback node to its graph node ID.