executeCommands

View sourceexecuteCommands(world: World): void

Applies the deferred commands currently queued for a World.

The function first looks up the world’s CommandQueue and drains it. It then calls each drained command’s execute(world) in FIFO order. Draining replaces the queue before any command runs, so commands added during execution remain queued for the next call. If a command throws, execution stops and the error propagates; already drained commands are not requeued. The lookup asserts when the world has no CommandQueue.

Register this function directly with Schedule#add when deferred mutations should be applied at that point in a schedule. The CommandsPlugin registers it for the app’s core schedule phases and installs the required queue automatically.

Examples

import { CommandQueue, executeCommands } from '@wimaengine/command'
import { Schedule } from '@wimaengine/schedule'
import { World } from '@wimaengine/ecs'

const world = new World()
world.setResource(new CommandQueue())

const schedule = new Schedule()
schedule.add(executeCommands)
schedule.run(world)

Parameters

NameDescriptionDefault
world

World whose command queue is drained and executed.

—

Throws

If world does not contain a CommandQueue.