Skip to content

Class: CorrelationTracker

Makaio Framework


Makaio Framework / bus-core / CorrelationTracker

Defined in: ../../../packages/bus-core/src/utils/correlation-tracker.ts:53

Tracks correlation IDs for request-response matching.

Provides automatic timeout handling and cleanup for pending requests.

const tracker = new CorrelationTracker();
// Track a request with 5 second timeout
const promise = tracker.track('correlation-123', 5000);
// Later, resolve when response arrives
tracker.resolve('correlation-123', { data: 'result' });
// Or reject on error
tracker.reject('correlation-123', new Error('Failed'));

new CorrelationTracker(): CorrelationTracker

Defined in: ../../../packages/bus-core/src/utils/correlation-tracker.ts:61

Create a new correlation tracker.

CorrelationTracker

cancel(correlationId, error?): void

Defined in: ../../../packages/bus-core/src/utils/correlation-tracker.ts:197

Cancel a pending request and remove its correlation entry.

string

Correlation ID for the request

Error

Optional cancellation error

void


cleanup(): void

Defined in: ../../../packages/bus-core/src/utils/correlation-tracker.ts:206

Clean up all pending requests.

Clears all timeouts and rejects all pending requests with a disconnection error.

void


reject(correlationId, error): void

Defined in: ../../../packages/bus-core/src/utils/correlation-tracker.ts:179

Reject a pending request.

Clears the timeout and removes the request from tracking.

string

Correlation ID for the request

Error

Error to reject with

void


resolve(correlationId, result): void

Defined in: ../../../packages/bus-core/src/utils/correlation-tracker.ts:159

Resolve a pending request.

Clears the timeout and removes the request from tracking.

string

Correlation ID for the request

unknown

Response result

void


track(correlationId, timeout, signal?): Promise<unknown>

Defined in: ../../../packages/bus-core/src/utils/correlation-tracker.ts:77

Track a pending request.

Returns a promise that resolves when the response arrives or rejects on timeout. When timeout is 0, no automatic timeout is set — the promise stays open until resolve() or reject() is called externally (e.g. by the caller’s own AbortSignal or pTimeout wrapper).

string

Correlation ID for the request

number

Timeout in milliseconds; 0 means no automatic timeout

AbortSignal

Optional AbortSignal to cancel and cleanup the pending entry

Promise<unknown>

Promise that resolves with the response result