Skip to main content

Function: buildConcurrentBatchRequests()

Gala Launchpad SDK 9.0.0-rc.5


Gala Launchpad SDK 9.0.0-rc.5 / index / buildConcurrentBatchRequests

Function: buildConcurrentBatchRequests()

buildConcurrentBatchRequests<T>(urls, batchSize, fetcher, options?): Promise<T[]>

Defined in: packages/launchpad-sdk/dist/utils/api-patterns.d.ts:83

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.

Type Parameters​

T​

T

Type of data returned by the fetcher function

Parameters​

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?​

Additional options (logger, timeout)

logger?​

Logger

timeout?​

number

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