setWorld

Override or reset the cached World instance used by the workflow runtime.

Overrides the cached World instance that getWorld() returns. Use it to inject a World constructed with explicit configuration (rather than environment variables), or pass undefined to clear the cache so the next getWorld() call reinitializes from the current environment.

import { setWorld, getWorld } from "workflow/runtime";
import type { World } from "@workflow/world";
declare const customWorld: World; // @setup

setWorld(customWorld);
const world = await getWorld(); // resolves customWorld

API signature

Parameters

ParameterTypeDescription
worldWorld | undefinedThe World instance to use, or undefined to reset the cache and reinitialize from environment variables on next access

Returns

This function does not return a value.

Example: Reset after environment changes

import { setWorld, getWorld } from "workflow/runtime";

process.env.WORKFLOW_TARGET_WORLD = "@workflow/world-local";
setWorld(undefined); // clear the cached instance

const world = await getWorld(); // reinitialized with new configuration
  • getWorld() - Resolve the cached World instance.
  • createWorld() - Construct a fresh World from environment configuration.