Schedule

View source

Represents an ordered collection of executable callbacks.

Each callback is enabled when appended. Use Schedule#add to append callbacks and Schedule#run to invoke enabled callbacks in append order with a world.

Examples

import { World } from '@wimaengine/ecs'
import { Schedule } from '@wimaengine/schedule'

const world = new World()
const schedule = new Schedule()

schedule.add((world) => {
  console.log('running a callback', world)
})

schedule.run(world)

Constructor


constructor()

Methods


add(system: object): number

View source

Appends an executable callback to the schedule and enables it.

The returned number is the callback’s zero-based position. Schedule#run considers callbacks in append order, and adding a callback does not execute it immediately.

Parameters

NameDescriptionDefault
system

Executable callback to append.

—

Returns

The zero-based id of the appended callback.

run(world: World, errorHandler?: object): void

View source

Invokes each enabled executable callback in append order.

The world argument is passed as the only argument to every enabled callback and as the second argument to errorHandler. Disabled entries are skipped without being called.

If an enabled callback throws, errorHandler receives the normalized error and the same world. Existing Error values are passed through; thrown strings become new Error(error), and other thrown values become new Error(String(error)). When no handler is provided, the default handler rethrows the normalized error. A custom handler that returns lets execution continue with the next callback; if it throws, run exits with that handler error.

Parameters

NameDescriptionDefault
world

World forwarded to each enabled callback and the error handler.

—
errorHandler?

Optional handler for callback errors.

—

Throws

If the default error handler rethrows a normalized callback error or a custom error handler throws.