Skip to content

ConnectionManager

Defined in: packages/client/src/lib/connection-manager/connection-manager.ts:70

Manages connection lifecycle, retry logic, and circuit breaker patterns for Maelstrom engine connections.

Features:

  • Owns its own TanStack Store for connection state
  • TypedEmitter-based events exposed via events: EventSubscriber
  • Exponential backoff retry logic with configurable options
  • Circuit breaker pattern for fault tolerance
  • Auto-reconnect on unexpected disconnections
const manager = new ConnectionManager(connector, {
maxRetries: 3,
initialDelayMs: 1000,
});
await manager.connect();
manager.events.on('connection_status_changed', (event) => {
console.log(`Connection: ${event.status}`);
});

new ConnectionManager(connector, options): ConnectionManager

Defined in: packages/client/src/lib/connection-manager/connection-manager.ts:94

EngineConnector

ConnectionManagerOptions

ConnectionManager

readonly events: EventSubscriber<ConnectionManagerEvents>

Defined in: packages/client/src/lib/connection-manager/connection-manager.ts:73


readonly store: Store<ConnectionManagerState>

Defined in: packages/client/src/lib/connection-manager/connection-manager.ts:71

connect(): Promise<void>

Defined in: packages/client/src/lib/connection-manager/connection-manager.ts:122

Establishes a connection to the engine with retry logic.

If the circuit breaker is open, this will throw an error immediately. Otherwise, it will attempt to connect with exponential backoff retry.

Startup waits for this Connector’s pending shutdowns owned by this manager. Superseded or disposed attempts do not dial after that wait.

This is the deliberate, user-initiated entry point, so it always starts with a full maxRetries budget: connectionRetryCount is reset to 0 here regardless of what a previous connect/disconnect cycle left behind. (The automatic-reconnect path is different — it only resets the count after a connection survives stabilityThresholdMs, so a server that accepts-then-immediately-closes still exhausts the budget. That delayed reset is unaffected by this one.)

Promise<void>


disconnect(): Promise<void>

Defined in: packages/client/src/lib/connection-manager/connection-manager.ts:145

Disconnects from the engine and cleans up connection state.

Promise<void>


dispose(): Promise<void>

Defined in: packages/client/src/lib/connection-manager/connection-manager.ts:255

Permanently disposes the ConnectionManager and releases all resources. Waits for current and outgoing Connector shutdowns. After disposal, the ConnectionManager cannot be reused.

Promise<void>