ActionManager
Defined in: packages/client/src/lib/command-processor/action-manager.ts:55
ActionManager handles action execution for vessel instances.
Components register typed action runners per instance to handle actions. Actions are executed:
- In parallel across different instances
- Sequentially within the same instance (respects executionPlan order)
The manager includes a waitForReady mechanism to handle race conditions where the server sends actions before components have registered their runners.
Example
Section titled “Example”const store = new Store(createInitialState());const actionManager = new ActionManager();
// Register typed action handlers for a specific instanceactionManager.registerRunner('instance-1', { selectOrder: async (params) => { // params is fully typed based on vessel definition setSelectedOrderId(params.orderId); return ok(undefined); }, closeOrderDetails: async () => { setSelectedOrderId(null); return ok(undefined); },});
// Execute actions from a server responseconst result = await actionManager.executeActions(response.executionPlan);console.log(`Executed ${result.actions.length} actions`);Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ActionManager(
options?):ActionManager
Defined in: packages/client/src/lib/command-processor/action-manager.ts:63
Parameters
Section titled “Parameters”options?
Section titled “options?”executionTimeoutMs?
Section titled “executionTimeoutMs?”number
logger?
Section titled “logger?”readinessTimeoutMs?
Section titled “readinessTimeoutMs?”number
Returns
Section titled “Returns”ActionManager
Methods
Section titled “Methods”dispose()
Section titled “dispose()”dispose():
void
Defined in: packages/client/src/lib/command-processor/action-manager.ts:302
Release the manager: cancel every pending readiness wait so no timer outlives disposal, and settle its waiters as not-ready.
Waiters resolve false rather than rejecting so an in-flight
executeActions still returns its actions as skipped instead of
surfacing a rejection its callers do not expect. A disposed manager stays
silent and never schedules another readiness timer.
Returns
Section titled “Returns”void
executeActions()
Section titled “executeActions()”executeActions(
executionPlan):Promise<BatchExecutionResult>
Defined in: packages/client/src/lib/command-processor/action-manager.ts:215
Execute all actions in the execution plan.
Actions are grouped by instance and executed:
- In parallel across different instances
- Sequentially within the same instance (respects executionPlan order)
Waits for runners to be ready before executing. Actions are skipped if no runner is registered within the timeout.
Parameters
Section titled “Parameters”executionPlan
Section titled “executionPlan”readonly ActionExecution[]
Array of actions to execute
Returns
Section titled “Returns”Promise<BatchExecutionResult>
Result of the batch execution
getRegisteredInstances()
Section titled “getRegisteredInstances()”getRegisteredInstances():
InstanceId[]
Defined in: packages/client/src/lib/command-processor/action-manager.ts:134
Get all registered instance IDs.
Returns
Section titled “Returns”InstanceId[]
Array of instance IDs with registered runners
hasRunner()
Section titled “hasRunner()”hasRunner(
instanceId):boolean
Defined in: packages/client/src/lib/command-processor/action-manager.ts:125
Check if a runner is registered for an instance.
Parameters
Section titled “Parameters”instanceId
Section titled “instanceId”InstanceId
The branded instance ID to check
Returns
Section titled “Returns”boolean
true if a runner is registered
registerRunner()
Section titled “registerRunner()”registerRunner<
V>(instanceId,runner):Unsubscribe
Defined in: packages/client/src/lib/command-processor/action-manager.ts:89
Register an action runner for a specific instance. The runner is an object with typed action handlers.
Type Parameters
Section titled “Type Parameters”V extends VesselDefinition
Parameters
Section titled “Parameters”instanceId
Section titled “instanceId”InstanceId
The branded instance ID this runner handles
runner
Section titled “runner”ActionRunner<V>
Object with action name -> handler function mapping
Returns
Section titled “Returns”Example
Section titled “Example”actionManager.registerRunner(InstanceId('instance-1'), { selectOrder: async (params) => { setSelectedOrderId(params.orderId); return ok(undefined); },});waitForReady()
Section titled “waitForReady()”waitForReady(
instanceId,timeoutMs?):Promise<boolean>
Defined in: packages/client/src/lib/command-processor/action-manager.ts:156
Wait for a runner to be registered for an instance. This handles the race condition where the server sends actions before React components have mounted and registered their runners.
Parameters
Section titled “Parameters”instanceId
Section titled “instanceId”InstanceId
The branded instance ID to wait for
timeoutMs?
Section titled “timeoutMs?”number = 5000
Maximum time to wait (default: 5000ms)
Returns
Section titled “Returns”Promise<boolean>
Promise that resolves to true if runner registered, false if the wait timed out or the manager was disposed
Example
Section titled “Example”const isReady = await actionManager.waitForReady(InstanceId('instance-1'), 3000);if (isReady) { // Runner is available, actions can execute}