index/functions/buildConcurrentBatchRequests.md
buildConcurrentBatchRequests<
T>(urls,batchSize,fetcher,options?):Promise<T[]>
Build and execute multiple API requests with concurrency limit
Maintains request order while respecting concurrency constraints. Useful for batch operations like fetching multiple token prices, pool data, or other resources that benefit from parallel requests but need rate limiting.
batch size
Type Parameters
| Type Parameter | Description |
|---|---|
T | Type of data returned by the fetcher function |
Parameters
| Parameter | Type | Description |
|---|---|---|
urls | string[] | Array of URLs or identifiers to fetch |
batchSize | number | Maximum number of concurrent requests |
fetcher | (url) => Promise<T> | Function to fetch data for each URL/identifier |
options? | { logger?: Logger; timeout?: number; } | Additional options (logger, timeout) |
options.logger? | Logger | - |
options.timeout? | number | - |
batch size
Returns
Promise<T[]>
Promise<T[]> Array of results in original order
Examples
Fetch multiple token prices with concurrency limit
const tokenNames = ['anime', 'dragon', 'mysterybox'];
const prices = await buildConcurrentBatchRequests(
tokenNames,
3, // 3 concurrent requests max
async (tokenName) => sdk.fetchTokenPrice(tokenName),
{ logger }
);
// Maintains original order: prices[0] = anime, prices[1] = dragon, etc.
Fetch pool data with concurrency control
const poolIds = ['pool-1', 'pool-2', 'pool-3', 'pool-4', 'pool-5'];
const pools = await buildConcurrentBatchRequests(
poolIds,
2, // 2 concurrent requests max
(poolId) => dexApi.getPoolInfo(poolId)
);
Since
6.5.0