Skip to content

@web-engine-dev/scheduler


@web-engine-dev/scheduler / SystemFn

Type Alias: SystemFn()<TContext>

SystemFn<TContext> = (context) => void | Promise<void>

A system function that can be scheduled.

Receives the context object and can optionally return a Promise for async execution.

Type Parameters

TContext

TContext = unknown

Parameters

context

TContext

Returns

void | Promise<void>

Example

typescript
interface GameContext {
  deltaTime: number;
  world: World;
}

// Synchronous system
const movementFn: SystemFn<GameContext> = (ctx) => {
  for (const entity of ctx.world.query(Position, Velocity)) {
    entity.get(Position).x += entity.get(Velocity).x * ctx.deltaTime;
  }
};

// Async system
const saveFn: SystemFn<GameContext> = async (ctx) => {
  await saveGameState(ctx.world);
};

Proprietary software. All rights reserved.