Runtime

Fx

Small explicit effect type used for systems and runtime orchestration.

Fx models delayed computation with typed success, failure, and environment channels. Expected failures are returned as Result values; exceptions are reserved for unexpected defects in user code.

Systems that cannot fail return nothing. A system returns an Fx when it has an expected failure: Fx.fail(...) rolls back the system's ECS writes and surfaces a typed SystemFailure from runtime.tick(...). map and flatMap compose such effects.

Examples

// Build one small delayed computation.
const program = Fx.map(Fx.succeed(1), (value) => value + 1)

// Execute it explicitly at the runtime boundary.
const result = Fx.runSync(program)

Functions

Minimal constructors and combinators for explicit delayed computations.

succeed

Source

Creates an effect that immediately succeeds with a value.

Use this for pure values that should still participate in the typed effect composition model.

sync

Source

Wraps a synchronous computation in an Fx.

This is the most common constructor for system implementations in the current runtime because systems are executed synchronously.

fail

Source

Creates an effect that returns one expected failure when run.

map

Source

Transforms the success value of an effect.

flatMap

Source

Sequences two effects, allowing the second one to depend on the first result.

access

Source

Reads the whole effect environment.

Use this when a system helper wants access to all declared services at once.

accessService

Source

Reads a single service from the environment by key.

This is useful for small helpers that need one dependency without threading the entire environment type manually.

provide

Source

Supplies the environment needed by an effect.

runSync

Source

Runs an effect that no longer requires any environment.

The runtime uses this at the edge after it has provided the services declared by a system spec.