# RequestCoordinator
Source: https://docs.maelstrom-ai.co/dev/reference/client/classes/requestcoordinator/
Documentation revision: 89a8f5e9d10cedcf0b30376d7846113f06f26120
SDK manifests in this build: @maelstrom-co/react@0.2.1, @maelstrom-co/client@0.2.1, @maelstrom-co/connectors@0.2.1, @maelstrom-co/protocol@0.2.1, @maelstrom-co/engine@0.2.1
These docs follow this source revision. Manifest versions do not prove release compatibility; verify the installed package exports before using an API.

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:67](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L67)

Manages the request lifecycle: sending requests, tracking in-flight state, emitting processing events, and coordinating flush promises.

## Example

```ts
const coordinator = new RequestCoordinator(connector);
coordinator.events.on('processing_completed', (e) => console.log(`Done in ${e.durationMs}ms`));

const response = await coordinator.send(envelope);
```

## Constructors

### Constructor

> **new RequestCoordinator**(`connector`, `options?`): `RequestCoordinator`

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:77](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L77)

#### Parameters

##### connector

[`EngineConnector`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/engineconnector/)

##### options?

[`RequestCoordinatorOptions`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/requestcoordinatoroptions/) = `{}`

#### Returns

`RequestCoordinator`

## Properties

### events

> `readonly` **events**: [`EventSubscriber`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/eventsubscriber/)<[`RequestCoordinatorEvents`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/requestcoordinatorevents/)\>

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:70](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L70)

* * *

### store

> `readonly` **store**: `Store`<[`RequestCoordinatorState`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/requestcoordinatorstate/)\>

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:72](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L72)

## Accessors

### isProcessing

#### Get Signature

> **get** **isProcessing**(): `boolean`

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:89](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L89)

##### Returns

`boolean`

* * *

### lastResponse

#### Get Signature

> **get** **lastResponse**(): `MaelstromResponse` | `null`

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:93](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L93)

##### Returns

`MaelstromResponse` | `null`

## Methods

### dispose()

> **dispose**(): `void`

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:212](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L212)

Retire request error reporting and reject queued flush promises. Outstanding sends still settle with their transport outcome; this method does not disconnect the transport.

#### Returns

`void`

* * *

### queueFlush()

> **queueFlush**(): `Promise`<`MaelstromResponse` | `null`\>

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:171](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L171)

Returns a promise that settles when the next response arrives or the next flush failure occurs. Use this to await an in-flight request when `isProcessing` is true and you want to coalesce with it.

Resolves to `null` rather than a response when the in-flight request it was coalescing with turns out to have been superseded (see [resolveFlushPromises](https://docs.maelstrom-ai.co/dev/reference/client/classes/requestcoordinator/#resolveflushpromises)) — mirroring the `null` a caller already gets back from `flushUpdates()` when there was nothing to report.

#### Returns

`Promise`<`MaelstromResponse` | `null`\>

* * *

### rejectFlushPromises()

> **rejectFlushPromises**(`error`): `void`

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:200](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L200)

Rejects all queued flush promises and clears the queue. Called when a flush fails before a response is available. The caller is responsible for logging if the error has not already been logged upstream — this method does not log.

#### Parameters

##### error

`Error`

#### Returns

`void`

* * *

### resolveFlushPromises()

> **resolveFlushPromises**(`response`): `void`

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:187](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L187)

Resolves all queued flush promises and clears the queue.

Pass `null` when the request they were coalescing with was discarded (e.g. fenced out by a connector swap) rather than actually applied — resolving with the discarded response itself would hand callers a layout that was never dispatched, and every fenced call site must settle these promises somehow or they hang until an unrelated later request happens to resolve them with an irrelevant response.

#### Parameters

##### response

`MaelstromResponse` | `null`

#### Returns

`void`

* * *

### send()

> **send**(`message`): `Promise`<`MaelstromResponse`\>

Defined in: [packages/client/src/lib/orchestrator/request-coordinator.ts:115](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/request-coordinator.ts#L115)

Send a request and preserve its transport outcome for the caller. Failures received after disposal no longer report a live request error.

#### Parameters

##### message

`ChartRequestMessage`

#### Returns

`Promise`<`MaelstromResponse`\>
