Class: CorrelationTracker
Makaio Framework / bus-core / CorrelationTracker
Class: CorrelationTracker
Section titled “Class: 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.
Example
Section titled “Example”const tracker = new CorrelationTracker();
// Track a request with 5 second timeoutconst promise = tracker.track('correlation-123', 5000);
// Later, resolve when response arrivestracker.resolve('correlation-123', { data: 'result' });
// Or reject on errortracker.reject('correlation-123', new Error('Failed'));Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CorrelationTracker():
CorrelationTracker
Defined in: ../../../packages/bus-core/src/utils/correlation-tracker.ts:61
Create a new correlation tracker.
Returns
Section titled “Returns”CorrelationTracker
Methods
Section titled “Methods”cancel()
Section titled “cancel()”cancel(
correlationId,error?):void
Defined in: ../../../packages/bus-core/src/utils/correlation-tracker.ts:197
Cancel a pending request and remove its correlation entry.
Parameters
Section titled “Parameters”correlationId
Section titled “correlationId”string
Correlation ID for the request
error?
Section titled “error?”Error
Optional cancellation error
Returns
Section titled “Returns”void
cleanup()
Section titled “cleanup()”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.
Returns
Section titled “Returns”void
reject()
Section titled “reject()”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.
Parameters
Section titled “Parameters”correlationId
Section titled “correlationId”string
Correlation ID for the request
Error
Error to reject with
Returns
Section titled “Returns”void
resolve()
Section titled “resolve()”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.
Parameters
Section titled “Parameters”correlationId
Section titled “correlationId”string
Correlation ID for the request
result
Section titled “result”unknown
Response result
Returns
Section titled “Returns”void
track()
Section titled “track()”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).
Parameters
Section titled “Parameters”correlationId
Section titled “correlationId”string
Correlation ID for the request
timeout
Section titled “timeout”number
Timeout in milliseconds; 0 means no automatic timeout
signal?
Section titled “signal?”AbortSignal
Optional AbortSignal to cancel and cleanup the pending entry
Returns
Section titled “Returns”Promise<unknown>
Promise that resolves with the response result