Skip to content

Class: BatchRequest ​

Batch request handler for parallel API calls

Constructors ​

Constructor ​

new BatchRequest(): BatchRequest

Returns ​

BatchRequest

Methods ​

add() ​

add<T>(key, promise): BatchRequest

Add a request to the batch

Type Parameters ​

NameTypeDescription
Tany

Parameters ​

NameTypeDescription
keystringUnique identifier for the request
promisePromise<T>Promise to execute

Returns ​

BatchRequest *? BatchRequest instance for chaining


clear() ​

clear(): void

Clear all requests from the batch

Returns ​

void *? ***

execute() ​

execute<T>(): Promise<T>

Execute all requests in parallel

Type Parameters ​

NameTypeDescription
TRecord<string, any>

Returns ​

Promise<T>

Object with results keyed by request names

Throws ​

Error if any request fails


executeSettled() ​

executeSettled<T>(): Promise<T>

Execute all requests and return results even if some fail

Type Parameters ​

NameTypeDescription
TRecord<string, any>

Returns ​

Promise<T>

Object with results or errors keyed by request names


getKeys() ​

getKeys(): string[]

Get all request keys

Returns ​

string[]

Array of request keys


isEmpty() ​

isEmpty(): boolean

Check if batch has any requests

Returns ​

boolean *? True if batch is empty


size() ​

size(): number

Get the number of requests in the batch

Returns ​

number *? Number of requests